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:

  1. create uilongpressgesturerecognizer , add gesture view in view controller.

  2. create method long press gesture can call when happens. call viewcontrollerlongpressed:.

  3. add new method gesture recognizer target.

  4. create 2 new methods moverocketdown , moverocketup.

  5. inside viewcontrollerlongpressed:, check state of sender. if it's uigesturerecognizerstatebegan , call moverocketdown. same uigesturerecognizerstateended , 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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -