UIGestureRecognizer 用于 UIView 的一部分
我在 iOS 应用程序中使用 UIGestureRecognizer,但遇到了一些问题。
我只希望手势在视图的某个区域起作用,因此我使用特定框架创建了一个新的 UIView 并将其添加到根视图中。手势工作正常,但现在唯一的问题是我无法单击新视图下方/后面的内容(根视图上的对象)。如果我将 userInteractionEnabled 设置为 NO,它会破坏手势,因此这不是一个选项。
我能做什么来解决这个问题?
谢谢。
I'm using UIGestureRecognizer in my iOS application and I'm having some issues.
I only want the gestures to work in a certain area of the view, so I made a new UIView with a specific frame and added it to the root view. The gestures are working fine with this, but the only issue now is that I can't click the stuff that is under/behind that new view (the objects that are on the root view). If I set userInteractionEnabled to NO, it breaks the gestures so that is not an option.
What can I do to fix that?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你也可以做:
某处。一般在 viewDidLoad() 上。然后你实现该方法:
Yo can also do:
somewhere. generally on viewDidLoad(). then you implement the method:
不要为手势识别器创建新视图。识别器实现了 locationInView: 方法。为包含敏感区域的视图进行设置。在handleGesture 上,对您关心的区域进行命中测试,如下所示:
0) 在包含您关心的区域的视图上执行所有这些操作。不要仅为手势识别器添加特殊视图。
1) 设置 mySensitiveRect
2) 创建手势识别器:
敏感矩形应在 myView 的坐标系中初始化,该坐标系与您附加识别器的视图相同。
Don't create a new view for your gesture recognizer. The recognizer implements a locationInView: method. Set it up for the view that contains the sensitive region. On the handleGesture, hit-test the region you care about like this:
0) Do all this on the view that contains the region you care about. Don't add a special view just for the gesture recognizer.
1) Setup mySensitiveRect
2) Create your gestureRecognizer:
The sensitive rect should be initialized in myView's coordinate system, the same view to which you attach the recognizer.