UIImageView 动画不显示在视图上

Sha*_*a G 2 iphone animation objective-c ipad

在我的 Iphone 应用程序中,我在 viewDidLoad() 方法中使用了以下 3 个图像的动画代码,并使用左变换加载此 ViewController。但是这些 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];
Run Code Online (Sandbox Code Playgroud)

Wal*_*ter 5

直到你告诉它开始动画才会开始。您将需要添加一个命令来启动动画。我还清理了你的 alloc/init 并添加了一个命令,使图像视图在没有动画时仍然保持显示。设置动画不会使图像出现。该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];
Run Code Online (Sandbox Code Playgroud)

最后,您的第三张图片缺少 r。我想你想要@"search.png"而不是@"seach.png"