2010-03-28 50 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"]; 
} 

我會離開的問題打開的時間長一點,以防有人知道爲什麼原來沒有工作。