I’m trying to implement UIPanGestureRecognizer for my view. How do I add multitouch? Below is the code from my view (a subclass of UIView). I would like to be able to know the location and velocity for all of the touches at the same time. The current code only prints out the location and velocity for one touch. Changing the properties minimumNumberOfTouches and maximumNumberOfTouches doesn’t work. Thank you very much for your help.
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
panGestureRecognizer.cancelsTouchesInView = NO;
[self addGestureRecognizer:panGestureRecognizer];
- (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer
{
CGPoint location = [panGestureRecognizer locationInView:panGestureRecognizer.view];
CGPoint velocity = [panGestureRecognizer velocityInView:panGestureRecognizer.view];
NSLog(@"Location: %@", NSStringFromCGPoint(location));
NSLog(@"Velocity: %@", NSStringFromCGPoint(velocity));
}
From the apple documentation for UIGestureRecogniser
For example:
(Objective-C)
(Swift)
As for velocity I believe there is only one value for it and there is no way to get the velocity of each touch without writing a custom method that calculates the difference between each touch over a series of calls. There is no guarantee that the touches will be at the same index each time however.
Note: As for the minimum and maximum number of touches, these will need to be set accordingly to get multiple touches.