【问题标题】:UICollectionView subview pan move without scrollingUICollectionView 子视图平移移动而不滚动
【发布时间】:2018-05-23 18:13:55
【问题描述】:

我有一个集合视图子视图的视图。如果我平移那个视图,我想移动那个视图。但是会发生什么是集合视图滚动一点,直到我在手势开始事件中关闭滚动。所以我试过不只是跳过这样的集合视图平移的触摸事件:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if gestureRecognizer == collectionView!.panGestureRecognizer && item.frame.contains(touch.location(in: self.collectionView!)) == true {
        return false
    }
    return true
}

但问题仍然存在,集合视图仍在滚动..

【问题讨论】:

  • 您可以尝试在CollectionView 上将UserInteractionEnabled 设置为false

标签: ios swift uicollectionview


【解决方案1】:

UICollectoinView 是 UIScrollView 的子类,尝试探索解决 UIScrollView 上的多手势的帖子,您可以从这里开始:

ScrollView gesture recognizer eating all touch events

【讨论】:

    【解决方案2】:

    好的,所以最终这样做(不确定这是否是最佳答案,但至少它有效):

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    
            if let panGesture = gestureRecognizer as? UIPanGestureRecognizer, let otherPanGesture = otherGestureRecognizer as? UIPanGestureRecognizer {
                if panGesture == self.collectionView?.panGestureRecognizer && item.frame.contains(otherPanGesture.location(in: self.collectionView!)) == true ||
                    otherPanGesture == self.collectionView?.panGestureRecognizer && item.frame.contains(panGesture.location(in: self.collectionView!)) == true {
                    return false
                }
                return true
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2019-01-27
      • 2015-09-24
      • 2015-01-27
      相关资源
      最近更新 更多