Reputation: 147
here is my code :
-(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];
}
This code doesn't work, I don't know why. I have always this warning on line "imageView = [[UIImageView alloc] initWithImage:image];" :Incompatible ObjectiveC type struct UIImageView*' expected struct UIImage*' when passing argument 1 of initWithImage from distinct Objective C type
Upvotes: 0
Views: 1406
Reputation: 1
Make sure that image
is a UIImageView and not a UIImage. You can only create animationImages for UIImageViews.
Upvotes: 0
Reputation: 17478
You can set animation images to UIImageView , and not to 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];
}
Upvotes: 2
Reputation: 69027
If you are doing:
image.animationImages = [NSArray arrayWithObjects:
then image
is an UIImageView
(review the code where you allocate it). That is the reason why you get the error, since initWithImage
expects an object of type UIImage:
- (id)initWithImage:(UIImage *)image
Either you did not mean image
to be an image view, or possibly you don't need to allocate a second UIImageView in your method and can just use image
.
Upvotes: 0