iPhone启动画面多任务处理
我使用下面的代码向 iPhone 添加了一个淡入淡出的启动屏幕。
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];
}
这是针对一个旧应用程序的,我现在正在为其启用多任务处理。我有一个问题,如果应用程序关闭(通过主页按钮或锁定),我想取消动画。我添加了以下代码以在应用程序关闭时删除启动视图
-(void) applicationDidEnterBackground:(UIApplication *)application
[splashView removeFromSuperview];
[splashView release];
}
如果在启动屏幕动画完成之前关闭应用程序,则应用程序会崩溃,因为启动屏幕在 applicationDidEnterBackground 中被删除,因此当调用startupAnimationDone时(在applicationDidEnterBackground之后)有没有什么可删除的,所以它崩溃了。
有没有办法取消applicationDidEnterBackground中的动画?
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 that 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在删除视图之前,您需要强制动画完成。您可以通过为终点创建一个新动画来做到这一点。设置非常短的持续时间,并确保使用 +setAnimationBeginsFromCurrentState: 方法从当前状态开始
较长的答案可以在 我对一个老问题的回答。
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 stateThe longer answer can be found in my answer to an old question.
在
[splashViewrelease]
之后调用splashView = nil
或调用
[splashView.layerremoveAllAnimations]
call
splashView = nil
after[splashView release]
or call
[splashView.layer removeAllAnimations]