2012-04-08 171 views
6

我怎么能在屏幕的底部移动一个UIImage在20秒(约35像素/秒)的屏幕顶部我不是说你应该自己拖动它,但它应该自动移动到顶部。谢谢移动uiimageview动画

回答

18

首先,apple doc是你的朋友。我在这里给你的所有信息都源于此。苹果还提供了很多示例代码,您绝对应该看看它。

你可以(很容易)完成这个任务的方式是使用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); 
}]; 

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

如果你不想使用块(^ {...代码...}上面位),你可以运行你的动画是这样的:

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

感谢的人,你真的。帮助我解决这个问题!我将搜索苹果样本并查看vids! – Xcodeuser 2012-04-09 13:04:38

+0

这绝对不是答案。我想知道为什么它是一个被接受的。 – 2016-08-17 11:47:08

+0

移动图像视图动画是我正在寻找 – 2016-08-17 11:47:33

3

如果我的理解是,你可以做自己的对象的动画,在这种情况下,尝试将beginAnimation

... 
initial position 

[UIView beginAnimation]; 
[UIView setAnimationDuration:dim/35.]; 
[UIView setAnimationCurve:[UIViewAnimationCurveLinear]; 

your animation 

[UIView commitAnimations]; 
... 

与此计算由第二位调光/ 35的计算来获得你的动画35px/s的

+0

谢谢你,你真的很有帮助! – Xcodeuser 2012-04-09 13:05:49