1

で画像のアニメーションを再生しようとしていUIAlertViewます。

これが私のコードです:

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];

ここで何が間違っていたのか教えてください。

4

1 に答える 1

1

これは、アニメーションの imageView フレーム サイズが原因です。アニメーションimageViewの特定のフレームサイズで割り当てる必要があります。そうしないと、メモリ空間を占有しません。nil オブジェクトが UIAlertView 内に追加されます。以下のコードを試してください

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];

このフレーム サイズを設定すると、正常に動作します。お役に立てば幸いです。ありがとう

于 2013-05-27T05:18:36.180 に答える