开发者

touchesBegan and touchesEnded on a UIWindow

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开发者_Go百科 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!


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.

  [self.nextResponder touchesBegan:touches withEvent:event];

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜