【问题标题】:Disable gesture on sideViews in contentView在 contentView 中禁用侧视图上的手势
【发布时间】:2017-02-25 09:36:40
【问题描述】:

我在我的 collectionView 单元格中显示三个视图。一个完整的在中间,在 contentView 的角落预览下一个和上一个。并使用 panGesture 向上滑动中间视图。如何在侧视图上禁用 panGesture?

这是图片:

我在内容视图上添加了 panGestureRecognizer。但我不想让侧视图识别手势,而且我想让侧面图像的颜色很淡。我该怎么做?

【问题讨论】:

    标签: swift swift3 uigesturerecognizer uipangesturerecognizer


    【解决方案1】:

    您可以使用 UIGestureRecognizerDelegate。实现方法:

    func wasDragged(gestureRecognizer: UIPanGestureRecognizer) {
    
        if gestureRecognizer.state == UIGestureRecognizerState.began {
            print("was dragged began")
        }
        if gestureRecognizer.state == UIGestureRecognizerState.changed {
            print("was dragged change \(gestureRecognizer.location(in: self.view))")
            testTouches(touches: gestureRecognizer.location(in: self.view))
        }
        if gestureRecognizer.state == UIGestureRecognizerState.ended {
            print("was dragged ended")
        }
    }
    

    比实现方法来测试触摸点:

    func testTouches(touches: CGPoint) {
        // Get location of touch
    
        let touchLocation = touches
        // Convert the location of the side views to this view controller's view coordinate system
        let sideViewFrame = self.view.convert(sideView.frame, from: sideView.superview)// Check if touch is inside side view
        if sideViewFrame.contains(touchLocation) {
                // do nothing
            }
            else {
                // do something
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多