模态视图和触摸开始

发布于 2024-09-09 15:44:28 字数 611 浏览 7 评论 0原文

这个问题是以下问题的后续问题:

UITouch - 事件未响应

我做了更多研究和我知道问题是什么,但我不知道如何解决,甚至不知道是否可以解决。我可能必须采取新的方法。

我有一个 RootViewController,并使用以下代码加载第二个 ViewController:

[self presentModalViewController:newWorkoutViewController animated:YES];

然后,我在 NewWorkoutViewController 中放置以下代码:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"New Workout Screen tapped");
}

该方法没有被执行,我认为这是因为它是一个模态视图。无论如何,是否可以在模式视图中检测屏幕上的点击。

谢谢 斯蒂芬

This question is a follow on from the following:

UITouch - Event not responding

I done more research and I know what the problem is, but I don't know how to solve it or even if it can be solved. I may have to take a new approach.

I have a RootViewController and from this I load a second ViewController using the following code:

[self presentModalViewController:newWorkoutViewController animated:YES];

I then have the following code in place in NewWorkoutViewController:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"New Workout Screen tapped");
}

This method is not being actioned, I think this is because its a modal view. Is there anyway to detect taps on the screen in a modal view.

Thanks
Stephen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

℉絮湮 2024-09-16 15:44:28

在视图控制器上定义相关方法,而不是在视图上。

Define the relevant methods on your view controller, not on your view.

南…巷孤猫 2024-09-16 15:44:28

你的假设是不正确的。以模态方式显示视图控制器与它无关。触摸在模态视图中的工作方式与在任何其他视图中的工作方式相同。您的视图很可能没有启用用户交互。您是如何创建辅助视图控制器的?

Your assumptions are incorrect. Displaying the view controller modally has nothing to do with it. Touches work the same in a modal view as they do in any other. In all likelihood, you don't have user interaction enabled on your view. How did you create your secondary view controller?

情深已缘浅 2024-09-16 15:44:28

仅当视图中没有接收事件的控件时,事件才会发送到 ViewController。例如,如果视图中有一个按钮,并且触摸该按钮,则该按钮将获取触摸事件,而不是 ViewController。

操作系统使用 pointInside:withEvent: 方法确定向何处发送事件,然后调用 hitTest:withEvent: 可以在视图中覆盖这些并查看哪些对象正在获取事件。

此外,任何隐藏的视图、已禁用用户交互的视图或 alpha 级别小于 0.1 的视图都会被 hitTest:withEvent 忽略:

Events are only sent to the ViewController if there are no controls in the view to receive the events. For example, if you have a button in your view, and touch the button, the button gets the touch event, not the ViewController.

The OS determines where to send events using the pointInside:withEvent: method and then calling hitTest:withEvent: It's possible to override these in your view and see what objects are getting the events.

Also, any views that are hidden, that have disabled user interaction, or have an alpha level less than 0.1 are ignored by hitTest:withEvent:

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