在我的 iPhone 应用程序中,我在 viewDidLoad() 方法中使用了以下代码来实现这 3 个图像的动画,并使用左变换来加载此 ViewController。但是这些imageView并没有显示在 View 上。
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];
最佳答案
在您指示动画开始之前,动画不会开始。您需要添加一个命令来启动动画。我还清理了你的 alloc/init 并添加了一个命令,使 ImageView 在没有动画时仍然保持显示。设置动画不会使图像出现。 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];
最后,你的第三张图片缺少一个 r。我认为你想要 @"search.png"
而不是 @"seach.png"
关于iphone - UIImageView 动画未显示在 View 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5475380/