2010-03-28 7 views
1

J'ai ce code qui devrait créer une image splash avec aucune animation ou un fondu entrant, puis appeler le code pour rejeter l'image après un délai. Le SplashViewAnimationNone fonctionne correctement et crée l'image en plein écran, mais le code de fondu masque l'image mais disparaît immédiatement.UIImageView Fade-In disparaît

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

Répondre

1

j'ai pu obtenir le même comportement avec une animation 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"]; 
} 

Je vais laisser la question ouverte pour un peu plus au cas où quelqu'un sait pourquoi l'original n'a pas fonctionné.