移动uiimageview动画

Nie*_*uil 6 iphone image uiimage ipad ios

我怎么能UIImage在20秒内(屏幕每秒约35个像素)从屏幕底部移动到屏幕顶部我并不是说你应该自己拖动它,但它应该自动移动到顶部.谢谢

Mal*_*eur 18

首先,apple doc是你的朋友.我在这里给你的所有信息都来源于此.Apple还提供了大量示例代码,您一定要看看它.

您可以(轻松)实现此目的的方法是使用UIView动画.假设您的图像具有UIImageView,则可以使用该animateWithDuration:(NSTimeInterval)duration animations:...方法.

例如:

[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);
}];
Run Code Online (Sandbox Code Playgroud)

您可以通过添加更多的选项动画,让完成块等,这都与"animateWithDuration"方法的变化实现更大胆的尝试.有很多关于UIView动画的教程,还有大量的文档.

如果您不想使用块(上面的^ {... code ...}位),您可以像这样运行动画:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:10.0f];
imageView.frame = ...
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)