触摸 uiview 内部和外部按钮时触发事件
我有一个视图覆盖到 iPhone 的相机视图上。在此视图中,我有一些 uibuttons,它们显示的位置取决于加速度计/指南针的值。 当用户在视图内触摸但没有在 uibuttons 内触摸时,我需要触发一个事件,我的意思是,与在 uibuttons 内触摸相反的操作。 有人知道有一种方法可以做到这一点吗? 谢谢!
I have a view overlayed to the iPhone's camera view. In this view I have some uibuttons that are displayed in positions depending of values from accelerometer/compass.
I need to fire an event when the user touch up inside the view but he doesn't touch up inside the uibuttons, I mean, the opposite action of touch up inside the uibuttons.
Anyone knows a kind to do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在视图上实现 UIResponder TouchesBegan:withEvent: 方法..
...,您将能够知道用户何时按下了按钮之外的按钮。
请参阅 UIResponder 类参考更多信息。
If you implement the UIResponder touchesBegan:withEvent: method..
...on your view, you'll be able to tell when the user has pressed outside of the buttons.
See the UIResponder Class Reference for more information.
例如,您可以将一个事件处理程序(IBAction)分配给 UiVeiw 及其 UIButtons,然后比较发送者参数:
you may e.g. assign one event handler (IBAction) to UiVeiw and its UIButtons and then compare sender parameter:
我尝试了你的选择,但它不起作用。我尝试触发事件的视图位于相机视图中的 TabBar 项目中,因此我认为响应者链不适用于它。
最后,我解决了使用覆盖视图第一响应者的问题:
[viewOverlay.view变成FirstResponder];
I tried your options but it doesn't work. The view that I tried to fire the event was in a TabBar item in a camera view, so I think the responders chain doesn't work with it.
Finally, I solved the problem doing the overlay view the first responder with:
[viewOverlay.view becomeFirstResponder];