【发布时间】: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