예제 #1
0
 private void UpdateContentOffset(bool animated, PagerScroll pagerScroll, CGRect toFrame, int toIndex)
 {
     if (pagerScroll != PagerScroll.No || (pagerScroll != PagerScroll.ScrollOnlyIfOutOfScreen && (toFrame.X < ContentOffset.X || toFrame.X >= (ContentOffset.X + Frame.Size.Width - ContentInset.Left))))
     {
         nfloat targetContentOffset = ContentSize.Width > Frame.Size.Width ? ContentOffsetForCell(toFrame, toIndex) : 0;
         SetContentOffset(new CGPoint(targetContentOffset, 0), animated);
     }
 }
        public void Move(nint fromIndex, nint toIndex, nfloat progressPercentage, PagerScroll pagerScroll)
        {
            SelectedIndex = progressPercentage > 0.5f ? toIndex : fromIndex;

            var fromFrame     = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(fromIndex, 0)).Frame;
            var numberOfItems = DataSource.GetItemsCount(this, 0);

            CGRect toFrame;

            if (toIndex < 0 || toIndex > numberOfItems - 1)
            {
                if (toIndex < 0)
                {
                    var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(0, 0));
                    toFrame = cellAtts.Frame;
                    toFrame.Offset(-cellAtts.Frame.Width, 0);
                }
                else
                {
                    var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(numberOfItems - 1, 0));
                    toFrame = cellAtts.Frame;
                    toFrame.Offset(cellAtts.Frame.Width, 0);
                }
            }
            else
            {
                toFrame = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(toIndex, 0)).Frame;
            }

            var targetFrame = fromFrame;

            targetFrame.Height = SelectedBar.Frame.Height;
            targetFrame.Width += (toFrame.Size.Width - fromFrame.Size.Width) * progressPercentage;
            targetFrame.X     += (toFrame.X - fromFrame.X) * progressPercentage;

            SelectedBar.Frame = new CGRect(targetFrame.X, SelectedBar.Frame.Y, targetFrame.Width, SelectedBar.Frame.Height);

            nfloat targetContentOffset = 0.0f;

            if (ContentSize.Width > Frame.Width)
            {
                var toContentOffset   = ContentOffsetForCell(toFrame, toIndex);
                var fromContentOffset = ContentOffsetForCell(fromFrame, fromIndex);

                targetContentOffset = fromContentOffset + ((toContentOffset - fromContentOffset) * progressPercentage);
            }

            var animated = Math.Abs(ContentOffset.X - targetContentOffset) > 30 || (fromIndex == toIndex);

            SetContentOffset(new CGPoint(targetContentOffset, 0), animated);
        }
예제 #3
0
 public void MoveToIndex(int toIndex, bool animated, SwipeDirection swipeDirection, PagerScroll pagerScroll)
 {
     selectedIndex = toIndex;
     UpdateSelectedBarPosition(animated, swipeDirection: swipeDirection, pagerScroll: pagerScroll);
 }
예제 #4
0
        public void UpdateSelectedBarPosition(bool animated, SwipeDirection swipeDirection, PagerScroll pagerScroll)
        {
            var selectedBarFrame = SelectedBar.Frame;

            NSIndexPath selectedCellIndexPath           = NSIndexPath.FromItemSection(new nint(selectedIndex), 0);
            UICollectionViewLayoutAttributes attributes = GetLayoutAttributesForItem(selectedCellIndexPath);
            CGRect selectedCellFrame = attributes.Frame;

            UpdateContentOffset(animated, pagerScroll: pagerScroll, toFrame: selectedCellFrame, toIndex: selectedCellIndexPath.Row);

            selectedBarFrame.Size = new CGSize(selectedCellFrame.Size.Width, selectedBarFrame.Size.Height);
            selectedBarFrame.X    = selectedCellFrame.X;

            if (animated)
            {
                UIView.Animate(0.3, () =>
                {
                    SelectedBar.Frame = selectedBarFrame;
                });
            }
            else
            {
                SelectedBar.Frame = selectedBarFrame;
            }
        }
예제 #5
0
        public void MoveFromIndex(int fromIndex, int toIndex, nfloat progressPercentage, PagerScroll pagerScroll)
        {
            selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex;

            CGRect fromFrame     = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(fromIndex, 0)).Frame;
            var    numberOfItems = DataSource.GetItemsCount(this, 0);

            CGRect toFrame;

            if (toIndex < 0 || toIndex > numberOfItems - 1)
            {
                if (toIndex < 0)
                {
                    var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(0, 0));
                    toFrame = CGRect.Inflate(cellAtts.Frame, -cellAtts.Frame.Size.Width, 0);
                }
                else
                {
                    var cellAtts = GetLayoutAttributesForItem(NSIndexPath.FromItemSection((numberOfItems - 1), 0));
                    toFrame = CGRect.Inflate(cellAtts.Frame, cellAtts.Frame.Size.Width, 0);
                }
            }
            else
            {
                toFrame = GetLayoutAttributesForItem(NSIndexPath.FromItemSection(toIndex, 0)).Frame;
            }


            CGRect targetFrame = fromFrame;

            if (this.SelectedBarWidth.HasValue)
            {
                targetFrame.Size = new CGSize(this.SelectedBarWidth.Value, SelectedBar.Frame.Size.Height);
                targetFrame.X    = fromFrame.X + (fromFrame.Width - this.SelectedBarWidth.Value) / 2;
                targetFrame.X   += (toFrame.X + (toFrame.Width - this.SelectedBarWidth.Value) / 2 - targetFrame.X) * progressPercentage;
            }
            else
            {
                var targetWidth = targetFrame.Size.Width + (toFrame.Size.Width - fromFrame.Size.Width) * progressPercentage;
                targetFrame.Size = new CGSize(targetWidth, SelectedBar.Frame.Size.Height);
                targetFrame.X   += (toFrame.X - fromFrame.X) * progressPercentage;
            }

            SelectedBar.Frame = new CGRect(targetFrame.X, SelectedBar.Frame.Y, targetFrame.Size.Width, SelectedBar.Frame.Size.Height);

            nfloat targetContentOffset = 0.0f;

            if (ContentSize.Width > Frame.Size.Width)
            {
                var toContentOffset   = ContentOffsetForCell(toFrame, toIndex);
                var fromContentOffset = ContentOffsetForCell(fromFrame, fromIndex);

                targetContentOffset = fromContentOffset + ((toContentOffset - fromContentOffset) * progressPercentage);
            }

            SetContentOffset(new CGPoint(targetContentOffset, 0), animated: false);
        }
 public void MoveTo(nint index, bool animated, SwipeDirection swipeDirection, PagerScroll pagerScroll)
 {
     SelectedIndex = index;
     UpdateSelectedBarPosition(animated, swipeDirection, pagerScroll);
 }
        private void UpdateSelectedBarPosition(bool animated, SwipeDirection swipeDirection, PagerScroll pagerScroll)
        {
            var selectedBarFrame = SelectedBar.Frame;

            var selectedCellIndexPath = NSIndexPath.FromItemSection(SelectedIndex, 0);
            var attributes            = GetLayoutAttributesForItem(selectedCellIndexPath);
            var selectedCellFrame     = attributes.Frame;

            UpdateContentOffset(animated, pagerScroll, selectedCellFrame, (selectedCellIndexPath as NSIndexPath).Row);

            selectedBarFrame.Width = selectedCellFrame.Width;
            selectedBarFrame.X     = selectedCellFrame.X;

            if (animated)
            {
                UIView.Animate(duration: 0.3, animation: () =>
                {
                    this.SelectedBar.Frame = selectedBarFrame;
                });
            }
            else
            {
                SelectedBar.Frame = selectedBarFrame;
            }
        }