简体   繁体   中英

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. But these imageView is not displayed on the 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];

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. 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.

 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. I think you want @"search.png" and not @"seach.png"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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