UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTapTap:)];
[self.view1 addGestureRecognizer:tapGesture];
[self.view2 addGestureRecognizer:tapGesture];
[tapGesture release];
在上面的代码中,只有对 view2
的点击被识别。如果我注释掉第三行,则可以识别对 view1
的点击。如果我是对的并且您只能使用一次手势识别器,我不确定这是一个错误还是它只需要更多文档。
最佳答案
UIGestureRecognizer
将与单个 View 一起使用。我同意文档参差不齐。那 UIGestureRecognizer
有一个单一的 view
属性给它了:
view
The view the gesture recognizer is attached to. (read-only)
@property(nonatomic, readonly) UIView *view
Discussion You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: method.
https://stackoverflow.com/questions/4747238/
相关文章:
objective-c - 有没有办法从 UITableView 中删除分隔线?
objective-c - registerForRemoteNotificationTypes :
ios - 我可以强制 UITableView 隐藏空单元格之间的分隔符吗?
objective-c - 在 Storyboard中,如何制作用于多个 Controller 的自
ios - 如果模态 ViewController 演示样式为 UIModalPresentatio
ios - 查看保存的 NSUserDefaults 的简单方法?