UIWindow 上的touchesBegan 和touchesEnded
我的 iPhone 游戏的 appDelegate 有一个“UIWindow window”成员变量。我将 UIImageView 添加到窗口并在游戏过程中移动它们。我想处理 UIWindow 上的触摸。 我怎样才能做到这一点?我必须子类化 UIWindow 吗?
我尝试将 touchesBegan:withEvent 和 touchesEnded:withEvent 方法添加到窗口,但它们没有被调用(可能是由于窗口被 UIImageViews 覆盖......例如游戏背景是一个 UIImageView 并且它覆盖了整个屏幕)。
干杯!
My iPhone game's appDelegate has a "UIWindow window" member variable. I add UIImageViews to the window and move them around during game play. I'd like to handle touches on the UIWindow. How can I do this? Do I have to subclass UIWindow?
I tried adding the touchesBegan:withEvent and touchesEnded:withEvent methods to the window but they are not called (possibly due to the window being covered by UIImageViews... for example the game background is a UIImageView and it covers the entire screen).
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果 UIImageView 覆盖窗口并且它们接受触摸,则触摸将不会被传递。您可以将这样的代码放置在 UIImageView 的 TouchesBegan 中,以将触摸传递到对象层中的下一个对象。
之前已经走过这条路(让窗口或主 UIView 控制我游戏中的很多东西),我鼓励您考虑让每个 UIImageView 捕获触摸事件并处理它们。然后 UIImageView 可以根据需要将信息传递给其他对象。
Apple 的 UIWindow 和查看编程指南似乎建议您应该尝试将代码保留在窗口之外并将其放入视图中。
Yes, if the UIImageViews cover the window and they accept touches the touches will not get passed through. You can place code like this in your UIImageView's touchesBegan to pass touches through to the next object in the layers of objects.
Having gone down this road before (have the window or a main UIView control a bunch of things in my game) I would encourage you to think about having each UIImageView capture touch events and deal with them. The UIImageView can then pass information along to other objects as needed.
Apple's documentation for UIWindow and the View Programming Guide seem to suggest that you should try to keep code outside of the window and place it into views.