开发者

UIImageView Fade-In Disappears

I have this code which should create a splash image with either no animation or a fade in, then call code to dismiss the image out after a delay. The SplashViewAnimationNone works fine and creates the full screen image, but the Fade code fades the image in but then immediately disappears.

- (void)startSplash {

    [[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubview:self];
    splashImage = [[UIImageView alloc] initWithImage:self.image];

    if (self.animationIn == SplashViewAnimationNone)
    {
        [self addSubview:splashImage];
    }
    else if (self.animationIn == SplashViewAnimationFade)
    {
        [self addSubview:splashImage];
        CABasicAnimation *animSplash = [CABasicAnimation animationWithKeyPath:@"opacity"];
        animSplash.duration = self.animationDelay开发者_C百科;
        animSplash.removedOnCompletion = NO;
        animSplash.fillMode = kCAFillModeForwards;
        animSplash.fromValue = [NSNumber numberWithFloat:0.0];
        animSplash.toValue = [NSNumber numberWithFloat:1.0];
        animSplash.delegate = self;
        [self.layer addAnimation:animSplash forKey:@"animateOpacity"];   
    }

    // Dismiss after delay.
    [self performSelector:@selector(dismissSplash) withObject:self afterDelay:self.delay];
}


I was able to get the same behavior with a CATransition animation:

else if (self.animationIn == SplashViewAnimationFade)
{
    // add the splash image
    [self addSubview:splashImage];

    // set up a transition animation
    CATransition *anim = [CATransition animation];
    [anim setDuration:self.animationDelay];
    [anim setType:kCATransitionPush];
    [anim setSubtype:kCATransitionFade];
    [anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[self layer] addAnimation:anim forKey:@"fade in"];
}

I'll leave the question open for a bit longer in case someone knows why the original didn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜