UIPanGestureRecognizer get cords of all touches
-
05-06-2021 - |
Domanda
I have added the following gesture recognizer:
UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(ViewDragging2:)];
[d2 setMinimumNumberOfTouches:2];
[d2 setMaximumNumberOfTouches:2];
[targetView addGestureRecognizer:d2];
and the method that get's fired when that event occurs is:
-(void)ViewDragging2:(UIPanGestureRecognizer*)sender {
// some point
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:targetView];
}
that get's me the point of one touch even though I touch with two fingers. How can I retrieve the cords of the first and second touch?
Soluzione
You can access all the touches using these methods:
(NSUInteger)numberOfTouches
(CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view
They are defined in the base class, UIGestureRecognizer.
Altri suggerimenti
Try the following code.
UIPanGestureRecognizer *d2 = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(ViewDragging2:)];
[d2 setMinimumNumberOfTouches:2];
[d2 setMaximumNumberOfTouches:2];
[targetView addGestureRecognizer:d2];
and the method that get's fired when that event occurs is:
-(void)ViewDragging2:(UIPanGestureRecognizer*)sender
{
// where touchIndex is either 0 or 1.
CGPoint location = [recognizer locationOfTouch:touchIndex inView:self.view];
}
check this link locationOfTouch and numberOfTouches
Regards, Neil.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow