user1580957
user1580957

Reputation:

Animate Images in UIAlertView

I am trying to play an animation of images in a UIAlertView.

Here is my code:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];

UIImageView *animation = nil;
animation.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"Comment-Edit-48.png"],[UIImage imageNamed:@"Share-48.png"],[UIImage imageNamed:@"Comment-Edit-48.png"],[UIImage imageNamed:@"Play-48.png"], nil];
[animation setAnimationRepeatCount:10];
animation.animationDuration = 1.5;
[animation startAnimating];

[alert addSubview:animation];


[alert show];
[alert release];

Can anyone please tell me what I did wrong here ?

Upvotes: 1

Views: 403

Answers (1)

chandan
chandan

Reputation: 2453

This is due to your animation imageView frame size. You need to alloc it with certain frame size of your animation imageView. If you don't do that then it will not occupy any memory space. A nil object would have been add inside UIAlertView. Try this below given code

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];

UIImageView *animation =[[UIImageView alloc] initWithFrame:CGRectMake(120, 50, 50, 45)];
animation.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"Comment-Edit-48.png"],[UIImage imageNamed:@"Share-48.png"],[UIImage imageNamed:@"Comment-Edit-48.png"],[UIImage imageNamed:@"Play-48.png"], nil];
[animation setAnimationRepeatCount:10];
animation.animationDuration = 1.5;
[animation startAnimating];

[alert addSubview:animation];


[alert show];
[alert release];

Set this frame size and it works fine. I hope it will help you. Thanks

Upvotes: 1

Related Questions