Catching drag events on a view
I can get button presses etc in Iphone. Is there away to catch drag events? Or do i need to make something custom to handle this?
Are there any complications if you have a mainview and inside 开发者_如何学Gothe main view you have 2 subviews. So basically 3 view on the sceen at once. Can all drag events go to the mainview?
Many Thanks, Code
You can implement the following method in a custom subclass of either UIView
or UIViewController
:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
Assuming there's one instance of UIViewController that loads the main view and its subviews, if you implement the method in your controller class it should get called for drag events in any of the views.
Touch events follow the responder chain from subviews up to their parent views and eventually to their view controllers. That means you can either subclass UIView
or UIViewController
and override the touch event handlers to implement the behavior you want.
In the case you describe, I'd recommend doing this in the view controller unless you're implementing a view you intend to reuse elsewhere.
精彩评论