ios - Moving a UIImageView from one point to another by touching any part of the screen -
i have been trying 1 uiimageview *rocket, original location have set in storyboard. has constraints initial position.
i want rocket move down 77 pixels, when screen touched or hold. once it's released, go original position.
all these actions, have 0.5s of animation not see jumps.
i hope have enough information here.
there 2 parts want: user action , ui animation.
it sounds want use uilongpressgesturerecognizer. sounds want have entire view inside view controller responsive long press.
to make uilongpressgesturerecognizer this:
create
uilongpressgesturerecognizer, add gesture view in view controller.create method long press gesture can call when happens. call
viewcontrollerlongpressed:.add new method gesture recognizer target.
create 2 new methods
moverocketdown,moverocketup.inside
viewcontrollerlongpressed:, check state of sender. if it'suigesturerecognizerstatebegan, callmoverocketdown. sameuigesturerecognizerstateended,moverocketup.
at point, have gesture recognizer responds user touch anywhere in view (unless there other gesture recognizer interfering view).
now, need animate rocket.
if know rocket start animation every time , end animation every time, i'd recommend creating constants 2 points. _rocketstartcenter , _rocketendcenter.
to animate rocket, method should work (i'm not @ computer check, apologize if off):
[uiview animateviewwithduration:0.5f animations:^{ _rocket.center = _rocketstartcenter; }]; i'd recommend using around 0.3-0.35 seconds animations, ios animations in range.
Comments
Post a Comment