I’m quiet new in ObjC and app programming. All I want to do is fade in an image. For that I did this:
-(IBAction)changeImg:(id)sender{
myImgView.image = [UIImage imageNamed:@"image.png"];
myImgView.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
myImgView.alpha = 1;
[UIView commitAnimations];
}
That works quiet good. But now I want to put the fade function into an own method and I don’t know how to call that method:
-(IBAction)changeImg:(id)sender{
myImgView.image = [UIImage imageNamed:@"image.png"];
[myImgView fadeIn:self];
}
-(void) fadeIn:(UIImageView *) imgFade{
imgFade.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
imgFade.alpha = 1;
[UIView commitAnimations];
}
When I call the method like this I get a warning:”‘UIImageView’ may not respond to ‘-fadeIn:’“
Can anyone help me please?
Sorry but I don’t get it to work.
The warning stays.
And when I do it like kuroutadori suggested:
...
self.alpha = 0;
...
I get an error:
“request for member ‘alpha’ in something not a structure or union“
You are declaring
fadeIn:on your current class (we would need more code to see which one it is) yet calling it on anUIImageViewinstance (in your case myImgView).You should either declare it privately in your current class implementation file (as Jonathan Grynspan suggested). Or if you’re extensively using this animation, put it into UIImageView itself through a category:
and then implement it with