这是我的代码:
-(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];” :不兼容的ObjectiveC类型struct UIImageView *'期望的结构UIImage *'从不同的Objective C类型传递initWithImage的参数1时
答案 0 :(得分:2)
您可以将动画图像设置为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];
}
答案 1 :(得分:0)
如果你这样做:
image.animationImages = [NSArray arrayWithObjects:
然后image
是UIImageView
(查看您分配代码的代码)。这就是你得到错误的原因,因为initWithImage
期望一个UIImage类型的对象:
- (id)initWithImage:(UIImage *)image
你不是说image
是图像视图,或者你可能不需要在方法中分配第二个UIImageView,而只能使用image
。
答案 2 :(得分:0)
确保image
是UIImageView而不是UIImage。您只能为UIImageViews创建animationImages。