Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

UIImageView alpha fade animation issues

I'm a newbie iPhone developer going very well, almost finished my first app minus this one issue which I am a little embarrassed to be asking but...

I have a UIImageView that I have animated to fade (alpha value) over the period of 60s. After the animation a UIButton displays. In addition by tapping you can force the alpha value of the UIImageView down as to make the animation appear faster. But I am having trouble determining when the alpha value of my UIImageView is below zero - so that I can display the button - even though the animation is still running. Here is my code:

- (void)fadeTheImageView
{
[fadeImageView setAlpha:1.0];

[UIView beginAnimations:@"theAnimation" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(yourAnimationHasFinished:finished:context :)];
[UIView setAnimationDuration:10];
[fadeImageView setAlpha:0.0];
[UIView commitAnimations];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ( fadeImageView.alpha <= 0.0 ) {
[saveButton setHidden:NO];
}
[fadeImageView setAlpha:(fadeImageView.alpha - 0.1)];
}

- (void)yourAnimationHasFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context;
{
[saveButton setHidden:NO];
}

The error is with the if ( fadeImageView.alpha <= 0.0 ) {
incompatible variable types.
I've tried everything.

Any help would be appreciated

iMac, Mac OS X (10.5.6)

Posted on Mar 8, 2009 11:15 PM

Reply
3 replies

Mar 9, 2009 1:45 AM in response to nicksayes

Hi Nick. I've only tested touchesEnded so far, since you said that was the only problem. I haven't been able to reproduce the "incompatible variable types" error, so don't know where that's coming from. However I did notice one thing that might be relevant: In my test runs ( fadeImageView.alpha <= 0.0 ) never becomes YES, and on second look I don't see how we can expect that since a view no longer catches touches when it's alpha goes to zero (I think you need alpha >= 0.02 to catch touch events).

Maybe there's more going on here that I'd see if I tested touchesEnded with the rest of your code and I'll try to do that tomorrow. Btw, it would help if you formatted your code so it could be pasted into a test bed verbatim. Do that like this:


[fadeImageView setAlpha:(fadeImageView.alpha - 0.1)];


The above lines produce:

[fadeImageView setAlpha:(fadeImageView.alpha - 0.1)];

Mar 9, 2009 12:51 PM in response to RayNewbie

Thanks

Its news to me that there is a limit of 0.02 alpha on touches - and strangely I'm not getting the incompatible variable types error any more. The alpha limit on touches doesn't fix the issue though.

I think the code

if (fadeImageView.alpha <= 0.3)

is simply ignored as the button (which is programmed to become visible with the condition above) becomes visible with 1 tap ... when the alpha is clearly higher than 0.3?

Hmmm?

Mar 9, 2009 1:14 PM in response to nicksayes

I've worked around the problem.
What I have done is to animate the alpha of the button along side the UIImageView.
So no need to rely on that conditional.


- (void)fadeTheImageView
{
UIImage *fadeImage = [UIImage imageNamed:@"Base.png"];
fadeImageView.image = fadeImage;
[fadeImageView setAlpha:1.0];
[saveButton setHidden:NO];
[saveButton setAlpha:-10.0];

[UIButton beginAnimations:@"saveButton" context:NULL];
[UIButton setAnimationDuration:30];
[saveButton setAlpha:1.0];
[UIButton commitAnimations];

[UIView beginAnimations:@"theAnimation" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(yourAnimationHasFinished:finished:context:)];
[UIView setAnimationDuration:30];
[fadeImageView setAlpha:0.0];
[UIView commitAnimations];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[saveButton setAlpha:(saveButton.alpha + 1.0)];
[fadeImageView setAlpha:(fadeImageView.alpha - 0.1)];
}
- (void)yourAnimationHasFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context;
{
[saveButton setAlpha:1.0];
}

UIImageView alpha fade animation issues

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.