如果这个问题已在其他地方得到解答,我提前道歉,我已经尝试过找到它,但没有运气。
我有一个UICollectionView占用了我的一半视图,每个单元格占据了视图的整个宽度。当我在细胞上滑动时,它可以完美滚动并更改图像。
我想在整个视图中添加一个手势,这样即使我在UICollectionView下方滑动,也可以在视图或标签上面说,滚动仍然会发生,内置功能就像func scrollViewDidEndDecelerating( scrollView:UIScrollView也将被调用。
有没有办法调用在UICollectionView(Cells)上滑动时调用的相同内置UICollectionView Swipe Gesture
我尝试了以下多种变体:
var colView = UICollectionView!
var swipeRight = UISwipeGestureRecognizer.init(target: colView, action: Selector("handleSwipe:"))
var swipeLeft = UISwipeGestureRecognizer.init(target: colView, action: Selector("handleSwipe:"))
swipeRight.direction = .Right
swipeLeft.direction = .Left
view.addGestureRecognizer(swipeRight)
view.addGestureRecognizer(swipeLeft)
我已经尝试打印出UICollectionView手势识别器,但要么没有正确解释它们,要么缺少某些东西
Optional([<UIScrollViewDelayedTouchesBeganGestureRecognizer: 0x7fec88c9df40; state = Possible; delaysTouchesBegan = YES; view = <UICollectionView 0x7fec890a2200>;
target= <(action=delayed:, target=<UICollectionView 0x7fec890a2200>)>>, <UIScrollViewPanGestureRecognizer: 0x7fec88c9e8d0; state = Possible; delaysTouchesEnded = NO; view = <UICollectionView 0x7fec890a2200>; target= <(action=handlePan:, target=<UICollectionView 0x7fec890a2200>)>; must-fail =
{
<UIScrollViewPagingSwipeGestureRecognizer: 0x7fec88c995d0; state = Possible; view = <UICollectionView 0x7fec890a2200>; target= <(action=_handleSwipe:, target=<UICollectionView 0x7fec890a2200>)>>
}>,
<UIScrollViewPagingSwipeGestureRecognizer: 0x7fec88c995d0; state = Possible; view = <UICollectionView 0x7fec890a2200>; target= <(action=_handleSwipe:, target=<UICollectionView 0x7fec890a2200>)>; must-fail-for =
{
<UIScrollViewPanGestureRecognizer: 0x7fec88c9e8d0; state = Possible; delaysTouchesEnded = NO; view = <UICollectionView 0x7fec890a2200>; target= <(action=handlePan:, target=<UICollectionView 0x7fec890a2200>)>>
非常感谢任何帮助