コード例 #1
0
        public static UICollectionViewLayoutAttributes FindNextItem(UICollectionViewLayoutAttributes[] items,
                                                                    UICollectionViewScrollDirection direction, int step, CGPoint scrollingVelocity, int currentIndex)
        {
            var velocity = direction == UICollectionViewScrollDirection.Horizontal
                                ? scrollingVelocity.X
                                : scrollingVelocity.Y;

            if (velocity == 0)
            {
                // The user isn't scrolling at all, just stay where we are
                return(items[currentIndex]);
            }

            // Move the index up or down by increment, depending on the velocity
            if (velocity > 0)
            {
                currentIndex = currentIndex + step;
            }
            else if (velocity < 0)
            {
                currentIndex = currentIndex - step;
            }

            // Make sure we're not out of bounds
            currentIndex = Clamp(currentIndex, 0, items.Length - 1);

            return(items[currentIndex]);
        }
コード例 #2
0
        public static UICollectionViewScrollPosition ToCollectionViewScrollPosition(this ScrollToPosition scrollToPosition,
                                                                                    UICollectionViewScrollDirection scrollDirection = UICollectionViewScrollDirection.Vertical, bool isLtr = false)
        {
            if (scrollDirection == UICollectionViewScrollDirection.Horizontal)
            {
                return(scrollToPosition.ToHorizontalCollectionViewScrollPosition(isLtr));
            }

            return(scrollToPosition.ToVerticalCollectionViewScrollPosition());
        }
コード例 #3
0
 public LayoutConfiguration Default()
 {
     ShowsFirstActionItem    = true;
     ShowsSecondActionItem   = true;
     ShowsCameraItem         = true;
     ShowsAssetItems         = true;
     ScrollDirection         = UICollectionViewScrollDirection.Horizontal;
     NumberOfAssetItemsInRow = 2;
     InterItemSpacing        = 1;
     ActionSectionSpacing    = 1;
     CameraSectionSpacing    = 10;
     SectionIndexForActions  = 0;
     SectionIndexForCamera   = 1;
     SectionIndexForAssets   = 2;
     FirstNameOfActionItem   = "Camera";
     SecondNameOfActionItem  = "Photos";
     return(this);
 }
コード例 #4
0
        static CGPoint GetViewportOffset(CGRect itemFrame, CGRect viewport, SnapPointsAlignment snapPointsAlignment,
                                         UICollectionViewScrollDirection scrollDirection)
        {
            if (scrollDirection == UICollectionViewScrollDirection.Horizontal)
            {
                if (snapPointsAlignment == SnapPointsAlignment.Start)
                {
                    return(new CGPoint(viewport.Left - itemFrame.Left, 0));
                }

                if (snapPointsAlignment == SnapPointsAlignment.End)
                {
                    return(new CGPoint(viewport.Right - itemFrame.Right, 0));
                }

                var centerViewport = Center(viewport);
                var centerItem     = Center(itemFrame);

                return(new CGPoint(centerViewport.X - centerItem.X, 0));
            }

            if (snapPointsAlignment == SnapPointsAlignment.Start)
            {
                return(new CGPoint(0, viewport.Top - itemFrame.Top));
            }

            if (snapPointsAlignment == SnapPointsAlignment.End)
            {
                return(new CGPoint(0, viewport.Bottom - itemFrame.Bottom));
            }

            var centerViewport1 = Center(viewport);
            var centerItem1     = Center(itemFrame);

            return(new CGPoint(0, centerViewport1.Y - centerItem1.Y));
        }
コード例 #5
0
        /// Returns size for item considering number of rows and scroll direction, if preferredWidthOrHeight is nil, square size is returned
        public CGSize SizeForItem(int numberOfItemsInRow, nfloat?preferredWidthOrHeight,
                                  UICollectionView collectionView,
                                  UICollectionViewScrollDirection scrollDirection)
        {
            switch (scrollDirection)
            {
            case UICollectionViewScrollDirection.Horizontal:
                var itemHeight = collectionView.Frame.Height;
                itemHeight -= collectionView.ContentInset.Top + collectionView.ContentInset.Bottom;
                itemHeight -= (numberOfItemsInRow - 1) * Configuration.InterItemSpacing;
                itemHeight /= numberOfItemsInRow;
                return(new CGSize(preferredWidthOrHeight ?? itemHeight, itemHeight));

            case UICollectionViewScrollDirection.Vertical:
                var itemWidth = collectionView.Frame.Width;
                itemWidth -= collectionView.ContentInset.Left + collectionView.ContentInset.Right;
                itemWidth -= (numberOfItemsInRow - 1) * Configuration.InterItemSpacing;
                itemWidth /= numberOfItemsInRow;
                return(new CGSize(itemWidth, preferredWidthOrHeight ?? itemWidth));

            default:
                throw new ArgumentException("Should be invoked only with UICollectionViewScrollDirection");
            }
        }
コード例 #6
0
ファイル: ItemsViewLayout.cs プロジェクト: MIliev11/Samples
 void Initialize(UICollectionViewScrollDirection scrollDirection)
 {
     ScrollDirection = scrollDirection;
 }
        void HandlePanGesture(UIPanGestureRecognizer sender)
        {
            if (sender.State == UIGestureRecognizerState.Changed)
            {
                fingerTranslation = sender.TranslationInView(this.CollectionView);
                if (_hasShouldAlterTranslationDelegateMethod)
                {
                    ((UICollectionViewDataSourceDraggable)this.CollectionView.DataSource).CollectionViewAlterTranslation(this.CollectionView, fingerTranslation);
                }

                IUICollectionViewLayoutWarpable /*UICollectionViewLayout*/ /*<UICollectionViewLayout_Warpable>*/ layout = (IUICollectionViewLayoutWarpable /*UICollectionViewLayout*/ /*<UICollectionViewLayout_Warpable>*/)this.CollectionView.CollectionViewLayout;
//				if (layout.RespondsToSelector(new Selector ("dragDirection")))
                {
                    UICollectionViewScrollDirection direction = (UICollectionViewScrollDirection)layout.DragDirection();
                    if (direction == UICollectionViewScrollDirection.Horizontal)
                    {
                        fingerTranslation.Y = 0;
                    }
                    else if (direction == UICollectionViewScrollDirection.Vertical)
                    {
                        fingerTranslation.X = 0;
                    }
                }

                mockCell.Center = mockCenter.Add(fingerTranslation);
                if (canScroll)
                {
                    IUICollectionViewLayoutWarpable /*UICollectionViewLayout*/ /*<UICollectionViewLayout_Warpable>*/ scrollLayout = (IUICollectionViewLayoutWarpable /*UICollectionViewLayout*/ /*<UICollectionViewLayout_Warpable>*/)this.CollectionView.CollectionViewLayout;

                    if (scrollLayout.ScrollDirection() == UICollectionViewScrollDirection.Vertical)
                    {
                        if (mockCell.Center.Y < (this.CollectionView.Bounds.GetMinY() + this.ScrollingEdgeInsets.Top))
                        {
                            this.SetupScrollTimerInDirection(ScrollingDirection.Up);
                        }
                        else
                        {
                            if (mockCell.Center.Y > (this.CollectionView.Bounds.GetMaxY() - this.ScrollingEdgeInsets.Bottom))
                            {
                                this.SetupScrollTimerInDirection(ScrollingDirection.Down);
                            }
                            else
                            {
                                this.InvalidatesScrollTimer();
                            }
                        }
                    }
                    else
                    {
                        if (mockCell.Center.X < (this.CollectionView.Bounds.GetMinX() + this.ScrollingEdgeInsets.Left))
                        {
                            this.SetupScrollTimerInDirection(ScrollingDirection.Left);
                        }
                        else
                        {
                            if (mockCell.Center.X > (this.CollectionView.Bounds.GetMaxX() - this.ScrollingEdgeInsets.Right))
                            {
                                this.SetupScrollTimerInDirection(ScrollingDirection.Right);
                            }
                            else
                            {
                                this.InvalidatesScrollTimer();
                            }
                        }
                    }
                }

                if (scrollingDirection > ScrollingDirection.Unknown)
                {
                    return;
                }

                PointF      point     = sender.LocationInView(this.CollectionView);
                NSIndexPath indexPath = this.IndexPathForItemClosestToPoint(point);
                this.WarpToIndexPath(indexPath);
                if (this.DropOnToDeleteView != null && this.DropOnToDeleteView.Superview != null)
                {
                    bool highlighted = this.DropOnToDeleteView.Frame.Contains(point);
                    this.DropOnToDeleteView.Highlighted = highlighted;
                    if (!highlighted)
                    {
                        PointF center   = this.DropOnToDeleteView.Center;
                        float  distance = (center.X - point.X) * (center.X - point.X) + (center.Y - point.Y) * (center.Y - point.Y);
                        this.DropOnToDeleteView.Alpha = (float)(2f - Math.Atan(distance / 10000.0f)) / 2f;
                    }
                    else
                    {
                        this.DropOnToDeleteView.Alpha = 1.0f;
                    }
                }
            }
        }
コード例 #8
0
        public static CGPoint AdjustContentOffset(CGPoint proposedContentOffset, CGRect itemFrame,
                                                  CGRect viewport, SnapPointsAlignment alignment, UICollectionViewScrollDirection scrollDirection)
        {
            var offset = GetViewportOffset(itemFrame, viewport, alignment, scrollDirection);

            return(new CGPoint(proposedContentOffset.X - offset.X, proposedContentOffset.Y - offset.Y));
        }
コード例 #9
0
        public static CGPoint FindAlignmentTarget(SnapPointsAlignment snapPointsAlignment,
                                                  CGPoint contentOffset, UICollectionView collectionView, UICollectionViewScrollDirection scrollDirection)
        {
            var inset  = collectionView.ContentInset;
            var bounds = collectionView.Bounds;

            switch (scrollDirection)
            {
            case UICollectionViewScrollDirection.Vertical:
                var y = FindAlignmentTarget(snapPointsAlignment, contentOffset.Y, inset.Top,
                                            contentOffset.Y + bounds.Height, inset.Bottom);
                return(new CGPoint(contentOffset.X, y));

            case UICollectionViewScrollDirection.Horizontal:
                var x = FindAlignmentTarget(snapPointsAlignment, contentOffset.X, inset.Left,
                                            contentOffset.X + bounds.Width, inset.Right);
                return(new CGPoint(x, contentOffset.Y));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #10
0
 public Layout(UICollectionViewScrollDirection scrollDirection)
 {
     ScrollDirection         = scrollDirection;
     MinimumInteritemSpacing = ZeroMinimumInteritemSpacing;
     MinimumLineSpacing      = ZeroMinimumLineSpacing;
 }
コード例 #11
0
 public LayoutState(CGSize size, UICollectionViewScrollDirection direction)
 {
     Direction = direction;
     Size      = size;
 }