我有这个代码应该创建一个没有动画或淡入的启动图像,然后调用代码在延迟后将图像排除。 SplashViewAnimationNone
工作正常并创建全屏图像,但淡化代码淡化图像但随后立即消失。
- (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];
}
答案 0 :(得分: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"];
}
如果有人知道为什么原版不起作用,我会把问题保持打开一段时间。