触摸 uiview 内部和外部按钮时触发事件

发布于 2024-10-08 21:33:02 字数 164 浏览 0 评论 0原文

我有一个视图覆盖到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天的雪花 2024-10-15 21:33:02

如果您在视图上实现 UIResponder TouchesBegan:withEvent: 方法..

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

...,您将能够知道用户何时按下了按钮之外的按钮。

请参阅 UIResponder 类参考更多信息。

If you implement the UIResponder touchesBegan:withEvent: method..

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

...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.

身边 2024-10-15 21:33:02

例如,您可以将一个事件处理程序(IBAction)分配给 UiVeiw 及其 UIButtons,然后比较发送者参数:

-(IBAction) viewClicked :(id) sender {
  if (id == myView) ...
}

you may e.g. assign one event handler (IBAction) to UiVeiw and its UIButtons and then compare sender parameter:

-(IBAction) viewClicked :(id) sender {
  if (id == myView) ...
}
喜爱皱眉﹌ 2024-10-15 21:33:02

我尝试了你的选择,但它不起作用。我尝试触发事件的视图位于相机视图中的 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];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文