void CenterAlignCellsInColumn(UICollectionViewLayoutAttributes preferredAttributes)
        {
            // Determine the set of cells above this one
            var index = preferredAttributes.IndexPath;
            var span  = _itemsLayout.Span;

            var column = index.Item / span;
            var start  = (int)column * span;

            // If this is the first cell in the column, we don't need to adjust
            if (index.Item > start)
            {
                var currentCenter = preferredAttributes.Frame.GetMidX();

                // Work our way through the column
                for (int n = start; n < index.Item; n++)
                {
                    // Get the layout attributes for each cell
                    var path = NSIndexPath.FromItemSection(n, index.Section);
                    var attr = LayoutAttributesForItem(path);

                    // And see if the midpoints line up with the new layout attributes for the current cell
                    var center = attr.Frame.GetMidX();

                    if (currentCenter - center > 1)
                    {
                        // If the midpoints don't line up (withing a tolerance), adjust the cell's frame
                        var cell = CollectionView.CellForItem(path);
                        cell.Frame = new CGRect(currentCenter - cell.Frame.Width / 2, cell.Frame.Top, cell.Frame.Width, cell.Frame.Height);
                    }
                }
            }
        }
예제 #2
0
        private void panBegan(CGPoint point)
        {
            if (!isActive)
            {
                return;
            }

            allItemsStartAndEndTime = dataSource.AllItemsStartAndEndTime();

            firstPoint = point;
            LastPoint  = point;

            var cell           = CollectionView.CellForItem(itemIndexPath) as CalendarItemView;
            var topDragRect    = CollectionView.ConvertRectFromView(cell.TopDragTouchArea, cell);
            var bottomDragRect = CollectionView.ConvertRectFromView(cell.BottomDragTouchArea, cell);

            if (topDragRect.Contains(point))
            {
                action = EditAction.ChangeStartTime;
            }
            else if (bottomDragRect.Contains(point))
            {
                action = EditAction.ChangeEndTime;
            }
            else if (cell.Frame.Contains(point))
            {
                action = EditAction.ChangeOffset;
            }
            else
            {
                action = EditAction.None;
            }

            selectionFeedback.Prepare();
        }
예제 #3
0
 public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath)
 {
     if (CollectionView.CellForItem(indexPath) is ShellSectionHeaderCell cell)
     {
         cell.Label.TextColor = _unselectedColor.ToUIColor();
     }
 }
예제 #4
0
 private void HandleHeaderTapGesture(NSObject obj)
 {
     if (obj is UITapGestureRecognizer gesture)
     {
         if (gesture.View is SelectableDateCollectionHeaderView header)
         {
             var  section           = GetSectionFromDateTime(header.DateTime);
             int  sectionIndex      = Sections.IndexOf(section);
             bool isSectionSelected = section.Selected;
             for (int i = 0; i < section.Images.Count; ++i)
             {
                 if (CollectionView.CellForItem(NSIndexPath.FromItemSection(i, sectionIndex)) is SelectableImageCollectionViewCell cell)
                 {
                     if (isSectionSelected)
                     {
                         UnselectImage(cell.Image.Asset, sectionIndex);
                         cell.UpdateSelectedState(false, true);
                         continue;
                     }
                     if (!SelectedImages.Contains(cell.Image.Asset))
                     {
                         if (SelectImageIfPossible(cell.Image.Asset, sectionIndex))
                         {
                             cell.UpdateSelectedState(true, true);
                         }
                     }
                 }
             }
         }
     }
 }
        public override void SetEditing(bool editing, bool animated)
        {
            base.SetEditing(editing, animated);
            addButton.Enabled    = !editing;
            deleteButton.Enabled = editing;
            CollectionView.AllowsMultipleSelection = editing;

            // Make Sure For VisibleItems Not SelectedItems!
            var indexes = CollectionView.IndexPathsForVisibleItems;

            foreach (var index in indexes)
            {
                var cell = CollectionView.CellForItem(index) as CollectionViewCell;
                cell.Editing = editing;
            }

            if (!editing)
            {
                NavigationController.ToolbarHidden = true;
            }
            else
            {
                NavigationController.ToolbarHidden = false;
            }
        }
        UIDragPreviewParameters PreviewParameters(NSIndexPath indexPath)
        {
            var cell = CollectionView.CellForItem(indexPath) as PhotoCollectionViewCell;
            var previewParameters = new UIDragPreviewParameters();

            previewParameters.VisiblePath = UIBezierPath.FromRect(cell.ClippingRectForPhoto);
            return(previewParameters);
        }
예제 #7
0
        private void stopEditingCurrentCellIfNotVisible()
        {
            var cellNotVisible = CollectionView.CellForItem(itemIndexPath) == null;

            if (cellNotVisible)
            {
                stopEditingCurrentCell();
            }
        }
예제 #8
0
        public void SetVisiblePercent(nfloat percent)
        {
            if (CollectionView.IndexPathsForVisibleItems.Length == 0)
            {
                return;
            }
            var path = CollectionView.IndexPathsForVisibleItems[0];
            var cell = CollectionView.CellForItem(path) as CurrentSongCollectionViewCell;

            cell?.UpdatePercent(percent);
        }
        InkView GetInkViewAtTouchLocation(InkTouchController inkTouchController, CGPoint location)
        {
            var indexPath = CollectionView.IndexPathForItemAtPoint(location);

            if (indexPath == null)
            {
                return(new InkView());
            }

            var cell = CollectionView.CellForItem(indexPath);

            return(GetInkView(cell));
        }
        public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var row = indexPath.Row;

            var item = ShellSection.Items[row];

            if (item != ShellSection.CurrentItem)
            {
                ShellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, item);
            }

            var cell = (ShellSectionHeaderCell)CollectionView.CellForItem(indexPath);

            cell.Label.TextColor = _selectedColor.ToUIColor();
        }
예제 #11
0
        public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var row = indexPath.Row;

            var item = ShellSectionController.GetItems()[row];

            if (item != ShellSection.CurrentItem)
            {
                ShellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, item);
            }

            if (CollectionView.CellForItem(indexPath) is ShellSectionHeaderCell cell)
            {
                cell.Label.TextColor = _selectedColor.ToPlatform();
            }
        }
예제 #12
0
        public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            base.ItemSelected(collectionView, indexPath);

            _manuallySelected = true;
            SelectedIndex     = indexPath.Row;

            UIView.AnimateNotify(0.3f, () =>
            {
                var cell            = CollectionView.CellForItem(indexPath);
                _tabIndicator.Frame = new CGRect(cell.Frame.Left, 0, cell.Frame.Width, 2);
            }, (finished) =>
            {
                _manuallySelected = false;
            });
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Update the selection UI
            int index = Array.FindIndex(availableFilterInfos, fInfo => fInfo.FilterName == selectedFilterName);

            if (index < 0)
            {
                return;
            }

            NSIndexPath indexPath = NSIndexPath.FromItemSection(index, 0);

            CollectionView.SelectItem(indexPath, false, UICollectionViewScrollPosition.CenteredHorizontally);
            UpdateSelectionForCell(CollectionView.CellForItem(indexPath));
        }
예제 #14
0
        public override async void ViewDidAppear(bool animated)
        {
            isVisible = true;
            base.ViewDidAppear(animated);
            await Task.Delay(50);

            scrollTocurrentSong();
            await Task.Delay(50);

            if (CollectionView.IndexPathsForVisibleItems.Length == 0)
            {
                return;
            }
            var path = CollectionView.IndexPathsForVisibleItems[0];
            var cell = CollectionView.CellForItem(path) as CurrentSongCollectionViewCell;

            cell?.SetNeedsLayout();
        }
예제 #15
0
        public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            coolTransitioningDelegate    = coolTransitioningDelegate ?? new CoolTransitioningDelegate();
            overlayTransitioningDelegate = overlayTransitioningDelegate ?? new OverlayTransitioningDelegate();

            overlay = overlay ?? new OverlayViewController();
            if (PresentationShouldBeAwesome)
            {
                overlay.TransitioningDelegate = coolTransitioningDelegate;
            }
            else
            {
                overlay.TransitioningDelegate = overlayTransitioningDelegate;
            }
            overlay.PhotoView = (PhotoCollectionViewCell)CollectionView.CellForItem(indexPath);

            PresentViewController(overlay, true, null);
        }
예제 #16
0
        public override void ReloadData()
        {
            if (ItemsSource != null && (ItemsSource as IList).Count > 0 && ((ItemsSource as IList).Count != CollectionView.NumberOfItemsInSection(0) || !CollectionView.VisibleCells.Any()))
            {
                CollectionView.PerformBatchUpdates(() =>
                {
                    var newItems = ItemsSource as IList;
                    if (newItems != null)
                    {
                        var indexes    = new NSIndexPath[newItems.Count];
                        var startIndex = ItemsSource == null ? 0 : ItemsSource.Count() - newItems.Count;
                        for (var i = 0; i < indexes.Length; i++)
                        {
                            indexes[i] = NSIndexPath.FromRowSection(startIndex + i, 0);
                        }

                        if (CollectionView.VisibleCells.Any())
                        {
                            CollectionView.ReloadItems(indexes);
                        }
                        else
                        {
                            CollectionView.InsertItems(indexes);
                        }
                    }
                    else
                    {
                        ReloadData();
                    }
                }, ok =>
                {
                    var path = NSIndexPath.FromRowSection(_selectedIndex, 0);

                    CollectionView.SelectItem(path, false, UICollectionViewScrollPosition.CenteredHorizontally);

                    var cell = CollectionView.CellForItem(path);
                    if (cell != null)
                    {
                        _tabIndicator.Frame = new CGRect(cell.Frame.Left, 0, cell.Frame.Width, 2);
                    }
                });
            }
        }
예제 #17
0
        public virtual void OnExternalScroll(UIScrollView scrollView)
        {
            if (_manuallySelected)
            {
                return;
            }

            var contentOffset = scrollView.ContentOffset;

            var delta = (contentOffset.X - scrollView.Bounds.Width) / scrollView.Bounds.Width;

            var currentCell = CollectionView.CellForItem(NSIndexPath.FromRowSection(SelectedIndex, 0));

            if (currentCell != null)
            {
                var currentIndicatorX = currentCell.Frame.Left;

                var nextCellIndex = SelectedIndex + (delta > 0 ? 1 : -1);
                if (nextCellIndex >= 0 && nextCellIndex < (ItemsSource as IList).Count)
                {
                    var nextCell = CollectionView.CellForItem(NSIndexPath.FromRowSection(nextCellIndex, 0));

                    if (nextCell != null)
                    {
                        var nextIndicatorX = nextCell.Frame.Left;

                        var distance = (nextIndicatorX - currentIndicatorX) * delta;

                        var widthDifference = nextCell.Frame.Width - currentCell.Frame.Width;

                        _tabIndicator.Frame = new CGRect(
                            currentCell.Frame.Left + (delta > 0 ? distance : -distance),
                            0,
                            currentCell.Frame.Width + widthDifference * Math.Abs(delta),
                            2
                            );
                    }
                }
            }
        }
예제 #18
0
        internal void SelectPuzzleManually(PuzzleData selectedPuzzle)
        {
            int index   = -1;
            int section = -1;

            if (puzzlesPxn.Contains(selectedPuzzle))
            {
                section = 0;
                index   = puzzlesPxn.IndexOf(selectedPuzzle);
            }
            else if (puzzlesCustom.Contains(selectedPuzzle))
            {
                section = 1;
                index   = puzzlesCustom.IndexOf(selectedPuzzle);
            }

            NSIndexPath path = NSIndexPath.FromItemSection(index, section);
            var         cell = CollectionView.CellForItem(path) as PuzzlesListCellViewController;

            cell.SetSelected();

            lastSelectedCell = cell;
        }
예제 #19
0
        public UIViewController GetViewControllerForPreview(IUIViewControllerPreviewing previewingContext, CGPoint location)
        {
            // Obtain the index path and the cell that was pressed.
            var indexPath = CollectionView.IndexPathForItemAtPoint(location);

            Console.WriteLine("ForPreview " + location.ToString() + " " + indexPath);

            if (indexPath == null)
            {
                return(null);
            }

            var cell = CollectionView.CellForItem(indexPath);

            if (cell == null)
            {
                return(null);
            }


            // Create a detail view controller and set its properties.
            var peekViewController = (PeekViewController)Storyboard.InstantiateViewController("peekvc");

            if (peekViewController == null)
            {
                return(null);
            }

            var peekAt = todoItems [indexPath.Row];

            peekViewController.SetTodo(peekAt);
            peekViewController.PreferredContentSize = new CGSize(0, 160);

            previewingContext.SourceRect = cell.Frame;

            return(peekViewController);
        }
예제 #20
0
        protected override void HandleLongPressGesture()
        {
            switch (LongPressGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                // we get the current item and draw a floating copy on it on the Collection View, so that it cannot be taken outside the bounds of the collection view
                // we get the copy usign RasterizedImage
                var currentIndexPath = CollectionView.IndexPathForItemAtPoint(LongPressGestureRecognizer.LocationInView(CollectionView));
                SelectedItemIndexPath = currentIndexPath;
                if (SelectedItemIndexPath == null)
                {
                    return;
                }

                if (!DataSource.CanMoveItemAtIndexPath(SelectedItemIndexPath))
                {
                    return;
                }

                var collectionViewCell = CollectionView.CellForItem(SelectedItemIndexPath);
                CurrentView = new UIView(collectionViewCell.Frame);

                collectionViewCell.Highlighted = true;
                var highlightedImageView = new UIImageView(RastertizedImage(collectionViewCell));
                highlightedImageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                highlightedImageView.Alpha            = 1.0f;

                collectionViewCell.Highlighted = false;
                var imageView = new UIImageView(RastertizedImage(collectionViewCell));
                imageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                imageView.Alpha            = 0.0f;

                CurrentView.AddSubview(imageView);
                CurrentView.AddSubview(highlightedImageView);
                CollectionView.AddSubview(CurrentView);
                CurrentViewCenter = CurrentView.Center;

                OnWillBeginDraggingItem(SelectedItemIndexPath);

                // animate the floating copy into existence
                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        CurrentView.Transform      = CGAffineTransform.MakeScale(1.1f, 1.1f);
                        highlightedImageView.Alpha = 0.0f;
                        imageView.Alpha            = 1.0f;
                    },
                               () =>
                    {
                        highlightedImageView.RemoveFromSuperview();
                        OnDidBegingDraggingItem(SelectedItemIndexPath);
                    });
                InvalidateLayout();
            }
            break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Ended:
            {
                var currentIndexPath = SelectedItemIndexPath;
                if (currentIndexPath == null)
                {
                    return;
                }
                SelectedItemIndexPath = null;
                CurrentViewCenter     = PointF.Empty;

                OnWillEndDraggingItem(currentIndexPath);

                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        var layoutAttributes  = LayoutAttributesForItem(currentIndexPath);
                        CurrentView.Transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
                        CurrentView.Center    = layoutAttributes.Center;
                    },
                               () =>
                    {
                        CurrentView.RemoveFromSuperview();
                        CurrentView = null;
                        InvalidateLayout();

                        OnDidEndDraggingItem(currentIndexPath);
                    });
            }
            break;
            }
        }
        protected override void HandleLongPressGesture()
        {
            switch (LongPressGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                // we try to grab the current seelected item and draw a floating copy of it on the Drag Surface
                // the copy is just an image of it using RasterizedImage
                var currentIndexPath = CollectionView.IndexPathForItemAtPoint(LongPressGestureRecognizer.LocationInView(CollectionView));

                SelectedItemIndexPath = currentIndexPath;
                if (SelectedItemIndexPath == null)
                {
                    return;
                }

                if (!DataSource.CanMoveItemAtIndexPath(SelectedItemIndexPath))
                {
                    return;
                }

                var collectionViewCell = CollectionView.CellForItem(SelectedItemIndexPath);

                var        tpoint = DragSurface.ConvertPointFromView(collectionViewCell.Frame.Location, CollectionView);
                RectangleF frame  = new RectangleF(tpoint.X, tpoint.Y, collectionViewCell.Frame.Size.Width, collectionViewCell.Frame.Size.Height);
                CurrentView = new UIView(frame);

                collectionViewCell.Highlighted = true;
                var highlightedImageView = new UIImageView(RastertizedImage(collectionViewCell));
                highlightedImageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                highlightedImageView.Alpha            = 1.0f;

                collectionViewCell.Highlighted = false;
                var imageView = new UIImageView(RastertizedImage(collectionViewCell));
                imageView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                imageView.Alpha            = 0.0f;

                CurrentView.AddSubview(imageView);
                CurrentView.AddSubview(highlightedImageView);
                DragSurface.AddSubview(CurrentView);         // add this to the top level view so that we can drag outside
                CurrentViewCenter = CurrentView.Center;

                OnWillBeginDraggingItem(SelectedItemIndexPath);

                // we animate the drawing out of the floating copy
                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        CurrentView.Transform      = CGAffineTransform.MakeScale(1.1f, 1.1f);
                        highlightedImageView.Alpha = 0.0f;
                        imageView.Alpha            = 1.0f;
                    },
                               () =>
                    {
                        highlightedImageView.RemoveFromSuperview();
                        OnDidBegingDraggingItem(SelectedItemIndexPath);
                    });
                InvalidateLayout();
            }
            break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Ended:
            {
                var currentIndexPath = SelectedItemIndexPath;
                if (currentIndexPath == null || CurrentView == null)
                {
                    return;
                }
                SelectedItemIndexPath = null;
                CurrentViewCenter     = PointF.Empty;

                OnWillEndDraggingItem(currentIndexPath);

                UIView.Animate(0.3, 0.0, UIViewAnimationOptions.BeginFromCurrentState,
                               () =>
                    {
                        var layoutAttributes  = this.LayoutAttributesForItem(currentIndexPath);
                        CurrentView.Transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
                        CurrentView.Center    = CollectionView.ConvertPointToView(layoutAttributes.Center, DragSurface);
                    },
                               () =>
                    {
                        CurrentView.RemoveFromSuperview();
                        CurrentView = null;
                        InvalidateLayout();

                        OnDidEndDraggingItem(currentIndexPath);
                    });
            }
            break;
            }
        }
        public override void ItemHighlighted(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var cell = CollectionView.CellForItem(indexPath);

            cell.Alpha = (nfloat)0.6;
        }