模态视图和触摸开始
这个问题是以下问题的后续问题:
我做了更多研究和我知道问题是什么,但我不知道如何解决,甚至不知道是否可以解决。我可能必须采取新的方法。
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在视图控制器上定义相关方法,而不是在视图上。
Define the relevant methods on your view controller, not on your view.
你的假设是不正确的。以模态方式显示视图控制器与它无关。触摸在模态视图中的工作方式与在任何其他视图中的工作方式相同。您的视图很可能没有启用用户交互。您是如何创建辅助视图控制器的?
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?
仅当视图中没有接收事件的控件时,事件才会发送到 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: