2012-01-04 72 views
1

我有1张图片,我希望它可以在屏幕上移动。在我的情况下,它是一个从左到右穿过屏幕的小型摩托车的图像。 我有没有办法把这一个图像&让它每移动一步使它像动画图像一样?而不是逐帧拍摄大量照片,并从中制作动画,因为在我的情况下,我有367张照片&它使项目非常大。 谢谢。ImageView动画

@property(nonatomic, strong) UIImage *animation; 

回答

0

您可以在显示的UIImageView它和动画视图本身:

UIImageView *imgView = [[UIImageView alloc] initWithImage:motorcycleImage]; 
[self.view addSubview:imgView]; 
[imgView release]; 

而当你想制作动画:

[UIView beginAnimations:NULL context:NULL]; 
[UIView setAnimationDuration:1.0]; 
CGRect rect = imgView.rect; 
rect.origin.x += 320 - rect.size.width; 
// EDIT: how to put the view on the bottom of the screen 
rect.origin.y += 480 - rect.size.height; 
imgView.rect = rect; 
[UIView commitAnimations]; 

希望它能帮助。

+0

谢谢,但它给了我2错误,其中代码中的矩形字:propery'rect'没有找到对象的类型'UIImageView *' – 2012-01-04 15:47:36

+0

谢谢我做到了,但我怎么能让摩托车进出屏幕从左到右重复动画。现在它在屏幕的顶部呈现,我希望它在底部。 – 2012-01-04 16:35:19

+0

修改其框架属性,使其出现在底部,并调用[UIView setAnimationRepeatCount]多少次你想重复动画 – 2012-01-04 18:36:45