开发者

iphone splash screen multi-tasking

I have added a fading splash screen to an iPhone with the code below

UIImageView *splashView;
..
..
..
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,20, 320, 460)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.8];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
splashView.frame = CGRectMake(-60, -60, 440, 600);
[UIView commitAnimations];

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
   [splashView removeFromSuperview];
   [splashView release];
}

This is for an old app tha开发者_Python百科t I am now enabling multi-tasking for. I have an issue where if the app is closed (via the home button or locked) I want to cancel the animation. I have added the following code to remove the splash view when the app is closed

-(void) applicationDidEnterBackground:(UIApplication *)application
   [splashView removeFromSuperview];
   [splashView release];
}

The app crashes if the app is closed before the splash screen animation completes as the splash screen in removed in applicationDidEnterBackground, so when startupAnimationDone gets called (after applicationDidEnterBackground) there is nothing to remove so it crashes.

Is there a way to cancel the animation in applicationDidEnterBackground?


You need to force your animation to finish before you remove the view. You can do that by creating a new animation to your end point. Set a very short duration and make sure you use the +setAnimationBeginsFromCurrentState: method to start from the current state

The longer answer can be found in my answer to an old question.


call splashView = nil after [splashView release]

or call [splashView.layer removeAllAnimations]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜