views:

960

answers:

2

Hi,

I would like to do a fade in and out of a UIImageView using different times, let's say, using the following parameters:

  • t = 0 ... UIImageView's alpha = 0
  • t = 0.5s ... UIImageView's alpha = 0.7
  • t = 0.7s ... UIImageView's alpha = 0

Is this possible to do with CAAnimation or other method? How can that be done?

thanks for any help!

+2  A: 

You should probably look into CAKeyframeAnimation. It'll let you set values for multiple time points.

greenisus
Thanks!!!!!!!!!
Digital Robot
A: 

UIView has a setAnimationDidStopSelector: method which you can use. Simply setup your fade in animation using a beginAnimations block and set the didStop selector to another method which contains only the fade out animation block. Each of these animation blocks can have different animation durations.

Something like this:

    [UIView beginAnimations:next context:context];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(fadeOut:finished:context:)];
    myView.alpha = 0.7;
    [UIView commitAnimations];

-(void)fadeOut:(NSString*)animationID finished:(BOOL)finished context:(void*)context  {
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationDuration:0.2];
    myView.alpha = 0.0;
    [UIView commitAnimations];
}
David Kanarek
thanks but I have tried this and the animation freezes for a millisecond between the first and second parts. It needs to be continuous.
Digital Robot