ios - Finding the position of UIPanGestureRecognizer -
i have uipangesturerecognizer
added view controller. want able swipe go next view controller (kind of camera on ios lockscreen).
my problem don't know how find position of view being panned.
- if user passes length , lets go want go next view controller.
- if user hasn't reached length , lets go want view go default state before panned up.
i know locationinview
haven't been able work in in scenario.
i know need use uigesturerecognizerstatechanged
, uigesturerecognizerstateended
these things, don't know how find position , set position. thanks.
here code:
- (void)pangesture:(uipangesturerecognizer *)recognizer{ if (recognizer.state == uigesturerecognizerstatechanged) { cgpoint t = [recognizer translationinview:self.view]; if (t.y < 0) { t = cgpointmake(0, t.y); } else { t = cgpointmake(0, t.y); } //look @ recognizer.view.center = cgpointmake(recognizer.view.center.x + t.x, recognizer.view.center.y + t.y); [recognizer settranslation:cgpointmake(0, 0) inview:self.view]; } else if (recognizer.state == uigesturerecognizerstateended) { //if view dragged past 100 px - go next view controller, if not go t bottom of screen } }
you life made harder resetting translationinview
each time translation changes. better served storing default / start position when gesture begins , setting new position each time default / start position , combined translationinview
of gesture.
in way won't drift due calculation errors , have default / start position can compare against , reset to, if required, when gesture ends.
Comments
Post a Comment