コード例 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //Calculate Cell Size for screen resolution
            CGSize CellSize = GetSize();

            /*
             * Initialize the collectionview layout
             */
            UICollectionViewFlowLayout layout = new UICollectionViewFlowLayout
            {
                SectionInset            = new UIEdgeInsets(20, 20, 20, 20),
                MinimumInteritemSpacing = 1,
                MinimumLineSpacing      = 10,
                ItemSize = CellSize                 //new SizeF(110, 110)
            };

            /*
             * Initialize the CollectionViewSource and UICollectionView
             */
            CollectionViewSource = new CollectionViewImageStackSource();
            CollectionViewSource.ImageViewSize = new SizeF((float)CellSize.Width, (float)CellSize.Height);

            CollectionView = new UICollectionView(UIScreen.MainScreen.Bounds, layout);
            CollectionView.BackgroundColor = AppColors.LIGHT_TEAL;
            var longPressGesture = new UILongPressGestureRecognizer(gesture =>
            {
                // Take action based on state
                switch (gesture.State)
                {
                case UIGestureRecognizerState.Began:
                    var selectedIndexPath = CollectionView.IndexPathForItemAtPoint(gesture.LocationInView(View));
                    if (selectedIndexPath != null)
                    {
                        CollectionView.BeginInteractiveMovementForItem(selectedIndexPath);
                    }
                    break;

                case UIGestureRecognizerState.Changed:
                    CollectionView.UpdateInteractiveMovement(gesture.LocationInView(View));
                    break;

                case UIGestureRecognizerState.Ended:
                    CollectionView.EndInteractiveMovement();
                    break;

                default:
                    CollectionView.CancelInteractiveMovement();
                    break;
                }
            });

            // Add the custom recognizer to the collection view
            CollectionView.AddGestureRecognizer(longPressGesture);

            CollectionView.ShowsHorizontalScrollIndicator = true;


            CollectionView.RegisterClassForCell(typeof(UserCell2), UserCell2.CellID);
            CollectionView.ShowsHorizontalScrollIndicator = true;
            CollectionView.Source = CollectionViewSource;
        }