【问题标题】:IUICollectionViewDelegateFlowLayout drag and drop feature: A cell below the cell being long pressed is getting movedUICollectionViewDelegateFlowLayout 拖放功能:正在长按的单元格下方的单元格正在移动
【发布时间】:2017-07-06 11:32:26
【问题描述】:

我已将以下手势识别器附加到我的收藏视图:

public void AttachLongPressGestureRecognizer()
        {
            // Create a custom gesture recognizer
            var longPressGesture = new UILongPressGestureRecognizer((gesture) =>
            {
                // Take action based on state
                switch (gesture.State)
                {
                    case UIGestureRecognizerState.Began:
                        var selectedIndexPath = this.MyCollectionView.IndexPathForItemAtPoint(gesture.LocationInView(View));

                        if (selectedIndexPath != null)
                        {
                            this.MyCollectionView.BeginInteractiveMovementForItem(selectedIndexPath);
                        }
                        break;

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

                    case UIGestureRecognizerState.Ended:
                        this.MyCollectionView.EndInteractiveMovement();
                        break;

                    default:
                        this.MyCollectionView.CancelInteractiveMovement();
                        break;
                }

            });

虽然拖放功能似乎可以正常工作,但收到的 selectedIndexPath 不正确。当我长按一个特定的单元格时,它下面的一个单元格会被拾取并移动。我正在使用以下内容根据屏幕大小调整单元格的大小:

[Export("collectionView:layout:sizeForItemAtIndexPath:")]
    public CoreGraphics.CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
    {
        var cellHeight = collectionView.Frame.Height * 0.3;
        var cellWidth = collectionView.Frame.Width * 0.45;
        return new CoreGraphics.CGSize(cellWidth, cellHeight);
    }

在同一个单元格上单击会返回正确的 indexPath,但长按会返回被按下单元格下方单元格的 indexPath。

【问题讨论】:

    标签: ios xamarin.ios uicollectionviewlayout


    【解决方案1】:

    这是因为其他视图的高度干扰了集合高度。

    【讨论】:

      猜你喜欢
      • 2013-04-17
      • 2015-05-05
      • 2013-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      相关资源
      最近更新 更多