简体   繁体   English

视图中不显示UIImageView动画

[英]UIImageView animation is not displayed on view

In my Iphone App, I used the following code for the animation of those 3 images in viewDidLoad() method and I use left transform to load this ViewController. 在我的Iphone应用程序中,我在viewDidLoad()方法中使用以下代码来处理这3个图像的动画,并使用左变换来加载此ViewController。 But these imageView is not displayed on the view. 但是这些imageView不会显示在视图上。

NSArray *newArray = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"search1.png"],
                                                    [UIImage imageNamed:@"search2.png"],
                                                    [UIImage imageNamed:@"seach3.png"],
                                                    nil];
UIImageView *imageView = [UIImageView alloc];
[imageView initWithFrame:CGRectMake(240, 60, 60, 30)];
imageView.animationImages = newArray;
imageView.animationDuration = 0.25;
imageView.animationRepeatCount = 3;
[self.view addSubview:imageView];

Animation won't start until you tell it to start. 直到你告诉它开始动画才会开始。 You will need to add a command to startAnimating. 您需要添加一个命令来启动动画。 I also cleaned up your alloc/init and I added a command to make the image view still keep showing when it is not animating. 我还清理了你的alloc / init,并添加了一个命令,使图像视图在不动画时仍然显示。 Setting an animation will not make the image appear. 设置动画不会使图像显示。 The image property is for the still image and the animationImages property is for the animating images of a UIImageView. image属性用于静止图像, animationImages属性用于UIImageView的动画图像。

 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 60, 60, 30)];
imageView.image = [UIImage imageNamed:@"search3.png"]; //This will be the image that is visible when it is NOT animating.


imageView.animationImages = newArray;
imageView.animationDuration = 0.25;
imageView.animationRepeatCount = 3;
[imageView startAnimating]; //This will make the animation start

[self.view addSubview:imageView];

Finally, your third image is missing an r. 最后,你的第三张图片缺少r。 I think you want @"search.png" and not @"seach.png" 我想你想要@"search.png"而不是@"seach.png"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM