Iphone animationImages数组的问题

Iphone animationImages数组的问题,iphone,arrays,xcode,animation,uiimageview,Iphone,Arrays,Xcode,Animation,Uiimageview,这是我的密码: -(void) createNewImage { image.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"oeufgrisé.png"], [UIImage imageNamed:@"abouffer_03.png"], [UIImage i

这是我的密码:

-(void) createNewImage {

image.animationImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"oeufgrisé.png"],
                         [UIImage imageNamed:@"abouffer_03.png"],
                         [UIImage imageNamed:@"boutonplay_03.png"],
                         [UIImage imageNamed:@"boutonpause_03.png"],
                         [UIImage imageNamed:@"abouffer_05.png"],
                         [UIImage imageNamed:@"mangeurcentremieu3_03.png"],nil];
[image setAnimationRepeatCount:10];
image.animationDuration =1.5;
[image startAnimating];      

imageView = [[UIImageView alloc] initWithImage:image];

}
这个代码不起作用,我不知道为什么。我总是在“imageView=[[UIImageView alloc]initWithImage:image];”:当从不同的目标C类型传递initWithImage的参数1时,不兼容的ObjectVec类型struct UIImageView*“expected struct UIImage*”,如果您执行以下操作:

image.animationImages = [NSArray arrayWithObjects:
然后,
image
是一个
UIImageView
(查看分配它的代码)。这就是出现错误的原因,因为
initWithImage
需要UIImage类型的对象:

- (id)initWithImage:(UIImage *)image

您不是想让
image
成为图像视图,或者您可能不需要在方法中分配第二个UIImageView,只需使用
image

可以将动画图像设置为UIImageView,而不是UIImage

-(void) createNewImage {
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];

    imageView.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"oeufgrisé.png"],
                             [UIImage imageNamed:@"abouffer_03.png"],
                             [UIImage imageNamed:@"boutonplay_03.png"],
                             [UIImage imageNamed:@"boutonpause_03.png"],
                             [UIImage imageNamed:@"abouffer_05.png"],
                             [UIImage imageNamed:@"mangeurcentremieu3_03.png"],nil];
    [imageView setAnimationRepeatCount:10];
    imageView.animationDuration =1.5;
    [imageView startAnimating]; 
    [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(setLastImage:) userInfo:nil repeats:NO];

 }

-(void)setLastImage:(id)obj
{
    [imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"mangeurcentremieu3_03.png"] waitUntilDone:YES];
}

确保
image
是UIImageView而不是UIImage。您只能为UIImageViews创建动画图像。

是的,但我想要的是,动画完成后,imageView为“mangeurcentremieu3_03.png”。您可以按照我提到的操作。15秒后(10次1.5秒动画),动画将结束,imageView将显示“mangeurcentremieu3_03.png”“图像。我已编辑我的答案,以便imageview在15秒后显示图像。