문제

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!

도움이 되었습니까?

해결책

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

다른 팁

if (imgDefault.alpha == 0.0) {
    CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration: 3.0];
        [UIView setAnimationDelegate: self];
        imgDefault.alpha = 1.0;
        [UIView commitAnimations];
}
else {
    CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration: 3.0];
        [UIView setAnimationDelegate: self];
        imgDefault.alpha = 0.0;
        [UIView commitAnimations];
}

hope it helps

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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top