UIWindow stops receiving touches after removing a subview from it
I'm using a subclass of UIWindow to handle touch event in all views of the app. I'm trying to implement a drag and drop mechanism.
When tapping and holding on a view, i remove that view and start dragging with the finger. problem is after i remove the view the window stop receiving touch events until i lift my finger and touch it again.
help?
EDIT: i found that aft开发者_Go百科er the subview is removed, the window is receiving touches but the touch phase is UITouchPhaseStationary and not UITouchPhaseMoved, even though there is only one UITouch in [event touches]; how is this possible?
I am not quite sure, but I think your problem is because your are trying to handle events in UIWindow
class, rather than UIViewController
class. UIWindow is not designed to do so. Why don't you try this:
- Add an instance of
UIViewController
class to your project. - Add the view of that
UIViewController
to yourUIWindow
instance. - Add the touch handling method to the
UIViewController
. - Add your first view to
UIViewController
. - Respond to touch event.
- Remove the first view from
UIViewController
, and bring in the second view, or whatever. (It is kind of swapping views under theUIViewController
, rather than in the instance ofUIWindow
.)
精彩评论