How could I make a UIImage move from the bottom of the screen, to the top of the screen in 20 seconds (about 35 pixels per seconds) I don’t mean you should drag it by yourself, but it should automatically move to the top. Thank you
How could I make a UIImage move from the bottom of the screen, to
Share
Firstly, apple doc is your friend. All of the information I’m giving you here is derived from this. Apple also provides a LOT of sample code, and you should definitely take a look at it.
The way you can (easily) accomplish this is using UIView animations. Assuming that you have a UIImageView for your image, you can use the
animateWithDuration:(NSTimeInterval)duration animations:...method.For example:
You could get fancier by adding more and more options to the animation, getting a completion block, etc. This is all achieved with variations of the ‘animateWithDuration’ method. There are tons of tutorials on UIView animations out there, and tons of documentation.
If you don’t want to use blocks (the ^{ …code…} bit above) you can run your animation like this: