我创建了第二个启动画面,在延迟后淡出。
我的实现应该工作正常,但好像我在操作系统中发现了一个缺陷。随着应用程序打开:
然后它会适当地显示我的自定义闪屏。但是,如果我:
然后它显示主视图,大约.5秒钟后,屏幕上出现闪屏并几乎直接淡出 - 这是一种不受欢迎的效果。
所以看来,如果我足够快地回到应用程序,那么它仍然停留在applicationWillResignActive中,然后在应用程序重新出现时转到applicationWillEnterForeground。
代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NJALoginViewController *loginViewController = [[NJALoginViewController alloc] init];
self.splashView = [[NJASplashView alloc] initWithFrame:self.window.frame];
self.window.rootViewController = loginViewController;
[self.window makeKeyAndVisible];
[self.window addSubview:self.splashView];
[self performSelector:@selector(removeSplashScreen) withObject:nil afterDelay:0.5];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.splashView setAlpha:1];
[self.window addSubview:self.splashView];
[self.window bringSubviewToFront:self.splashView];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[UIView animateWithDuration:.5 delay:.7 options:UIViewAnimationOptionCurveLinear animations:^{
[self.splashView setAlpha:0];
} completion:^(BOOL finished) {
if (finished) {
[self.splashView removeFromSuperview];
}
}];
}
- (void)removeSplashScreen
{
[UIView animateWithDuration:.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
[self.splashView setAlpha:0];
} completion:^(BOOL finished) {
if (finished) {
[self.splashView removeFromSuperview];
}
}];
}
任何想法如何解决这个问题?
答案 0 :(得分:0)
在我看来,如果您希望应用程序显示您的启动图像,那么显示启动图像的代码将位于app delegate中的applicationWillResignActive中。 因为您无法在后台处理UI组件。因此,您必须在输入后台之前处理UI组件。
像这样:- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
[self.splashView setAlpha:1];
[self.window addSubview:self.splashView];
[self.window bringSubviewToFront:self.splashView];
// add new code
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}