iPhone启动画面多任务处理

发布于 2024-10-18 16:31:41 字数 1329 浏览 7 评论 0原文

我使用下面的代码向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹梦到西洲 2024-10-25 16:31:41

在删除视图之前,您需要强制动画完成。您可以通过为终点创建一个新动画来做到这一点。设置非常短的持续时间,并确保使用 +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 state

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

绻影浮沉 2024-10-25 16:31:41

[splashViewrelease]之后调用splashView = nil

或调用[splashView.layerremoveAllAnimations]

call splashView = nil after [splashView release]

or call [splashView.layer removeAllAnimations]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文