objective c - Pan Gesture had ended location -
i'm trying have when pan gesture ends, checks see if end location within area, in case square. have following code, , more less works reason when pan ends in square, it's saying not.
-(void)panhandler:(uipangesturerecognizer*)recognizer{ cgpoint translation = [recognizer translationinview:self.view]; switch (recognizer.state){ case uigesturerecognizerstatebegan: _stickimage.center = cgpointmake(_stickimage.center.x + translation.x, _stickimage.center.y + translation.y); break; case uigesturerecognizerstatechanged: _stickimage.center = cgpointmake(_stickimage.center.x + translation.x, _stickimage.center.y + translation.y); [recognizer settranslation:cgpointmake(0, 0) inview:self.view]; break; case uigesturerecognizerstateended: nslog(@"ended"); if(translation.x > _rectview.frame.origin.x && translation.x < (_rectview.frame.origin.x + _rectview.frame.size.width)){ if(translation.y > _rectview.frame.origin.y && translation.y < (_rectview.frame.origin.y + _rectview.frame.size.height)){ nslog(@"in grid!"); } } else{ nslog(@"out of grid"); } break; default: break; }
}
can use translation x , y locations did? or how find if pan end location in square? appreciated thanks!
translationinview:
not give location of touch, tells how far touch has moved since last call settranslation:inview:
the method want locationinview:
cgpoint location = [recognizer locationinview:recognizer.view]; if(cgrectcontainspoint(_rectview.frame, location)){ nslog(@"inside!"); }
Comments
Post a Comment