gpt4 book ai didi

ios - UICollectionView 上的手势识别器未接收到手势

转载 作者:行者123 更新时间:2023-11-29 12:03:26 25 4
gpt4 key购买 nike

我有一个 ViewController,它有一个垂直滚动的 Collection View ,它占据了整个 View 。我希望能够在整个 Collection View (不仅仅是单元格)上获得滑动和平移手势,但我无法获得任何手势。我已尝试将手势识别器添加到 View 和 Collection View 中,但似乎都不起作用。

将手势识别器添加到 View

self.panEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
self.panEdgeGesture.delegate = self;
[self.collectionView addGestureRecognizer:self.panEdgeGesture];
[self.panEdgeGesture setEdges:UIRectEdgeRight];

然后我添加了这些功能:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch{

return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}

- (void)handlePan:(UISwipeGestureRecognizer *)sender
{
DebugLog(@"Received pan gesture");
}

Collection View 单元格能否阻止手势事件的触发?他们自己没有手势。

最佳答案

根据 UIScreenEdgePanGestureRecognizer's Class Reference :

After creating a screen edge pan gesture recognizer, assign an appropriate value to the edges property before attaching the gesture recognizer to your view. You use this property to specify from which edges the gesture may start. This gesture recognizer ignores any touches beyond the first touch.

所以将代码更改为:

self.panEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc];
[self.panEdgeGesture setEdges:UIRectEdgeRight];
initWithTarget:self action:@selector(handlePan:)];
self.panEdgeGesture.delegate = self;
[self.collectionView addGestureRecognizer:self.panEdgeGesture];

关于ios - UICollectionView 上的手势识别器未接收到手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35951432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com