getting touches in UIResponder API

2019-08-14 18:19发布

问题:

So, UIResponder has methods like:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

My question is, what's the difference between the touches parameter, and [event allTouches]?

回答1:

All sets of touches are stored within event.

However, for convenience Apple separately provides the touch that triggered the touchesBegan method to be invoked as a parameter.

If you searched through [event allTouches] and compared them to the UITouch within [touches anyObject], you would find a match.