问题
Lets say I have view1 which is intercepting touch events and view2 which is not.
Can view1 pass those events to view2 and call [view2 touchesBegin] [view2 touchesMoved]...etc?
回答1:
Yes, sometimes, maybe. The technique you're asking about is known as event forwarding. I'll refer you to the Forwarding Touch Events section of the Event Handling Guide for iOS, which says the following:
The classes of the UIKit framework are not designed to receive touches that are not bound to them; in programmatic terms, this means that the view property of the UITouch object must hold a reference to the framework object in order for the touch to be handled. If you want to conditionally forward touches to other responders in your application, all of these responders should be instances of your own subclasses of UIView.
So, if you're looking to forward events from one view to another and both views are instances of your own UIView subclass, event forwarding may work for you. If your view2
is an instance of a UIKit class, though -- say, UIScrollView or UITextView, you shouldn't be surprised to encounter problems. And even if it works now, it could easily break in the future. A little further on in the text, that section states this more simply:
Do not forward events to UIKit framework objects.
I'd urge you to read the entire section -- there's some good advice and an example that may help if you do decide to use event forwarding.
来源:https://stackoverflow.com/questions/8363286/call-another-objects-touches-begin-ios