我在我的collectionView单元格中显示三个视图。一个完整的中间和预览下一个和上一个在contentView的角落。并使用panGesture向上滑动中间视图。如何在侧视图中禁用panGesture?
以下是图片:Route Constraints in Web API
我在内容视图中添加了panGestureRecognizer。但是我不想让侧面视图识别这个手势,而且我想让侧面图像变得模糊不清。我怎么能这样做?
答案 0 :(得分:0)
您可以使用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
}
}