2010-03-28 56 views
1

我有这样的代码,它应该创建一个没有动画或淡入的闪屏图像,然后调用代码在延迟后关闭图像。 SplashViewAnimationNone工作正常,并创建全屏图像,但淡入淡出代码图像,但随后立即消失。UIImageView淡入消失

- (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; 
     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]; 
} 

回答

1

我能够用CATransition动画获得相同的行为:

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"]; 
} 

我会离开的问题打开的时间长一点,以防有人知道为什么原来没有工作。