Move uiimageview animation

How can I make the UIImage transition at the bottom of the screen, to the top of the screen in 20 seconds (about 35 pixels per second). I don’t want you to drag it yourself, but it should automatically move to the top. Thanks you

+6
source share
2 answers

First off, apple doc is your friend. All the information I give you is derived from this. Apple also provides many sample code, and you should definitely take a look at it.

You can (easily) accomplish this using the UIView animation. Assuming you have a UIImageView for your image, you can use the animateWithDuration:(NSTimeInterval)duration animations:... method.

For instance:

 [UIView animateWithDuration:10.0f animations:^{ //Move the image view to 100, 100 over 10 seconds. imageView.frame = CGRectMake(100.0f, 100.0f, imageView.frame.size.width, imageView.frame.size.height); }]; 

You can become more attractive by adding more and more animation options, getting a completion block, etc. All this is achieved using variations of the animateWithDuration method. There are tons of tutorials on animating UIView and tons of documentation.

If you do not want to use blocks (bit ^ {... code ...} above), you can run the animation as follows:

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:10.0f]; imageView.frame = ... [UIView commitAnimations]; 
+18
source

If I understand this, you can animate your own object, in this case try beginAnimation

 ... initial position [UIView beginAnimation]; [UIView setAnimationDuration:dim/35.]; [UIView setAnimationCurve:[UIViewAnimationCurveLinear]; your animation [UIView commitAnimations]; ... 

with this calculation dim / 35 calculations are in second place to get your animation 35px / s

+3
source

Source: https://habr.com/ru/post/912699/


All Articles