中的presentViewController

中的presentViewController

本文介绍了AppDelegate 中的presentViewController 与iOS8 中的延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 iOS7 中有一个完整的工作解决方案,它通过 AppDelegate 的 didFinishLaunching 中的 presentViewController 显示一个 LoginViewController.

So I had a full working solution in iOS7 that displays a LoginViewController via presentViewController in the AppDelegate's didFinishLaunching.

基本上我正在做这样的事情:

Basically I am doing something like this:

UIViewController *backgroundViewController = ...
self.window.rootViewController = backgroundViewController;
[self.window makeKeyAndVisible];

[self.window.rootViewController presentViewController:loginViewController
                                             animated:NO ...]

在 iOS8 中,我看到了一个跳跃.首先我看到 backgroundViewController 然后大约 1 秒后登录出现.

In iOS8 I see a jump. First I see the backgroundViewController then after about 1 second or so the login appears.

那么,我怎样才能在 iOS8 中防止这种跳转?

So, how can I prevent this jump in iOS8?

我看到大量开发人员有这个问题,但仍然没有找到解决办法.

I am seeing that are a ton of developers with this kind of problem but still didn't find a solution.

推荐答案

也是一个 hack(目前),但只有一行代码

Also a hack (for now), but just one line of code

在展示前将您展示的视图控制器的视图添加到窗口中

Add the view of the view controller you're presenting to the window before presentation

UIViewController *viewController = [[UIViewController alloc] init];
[viewController.view setBackgroundColor:[UIColor greenColor]];

//  Temporary iOS8 fix for 'presentation lag' on launch
[self.window addSubview:viewController.view];

[self.window.rootViewController presentViewController:viewController animated:NO completion:nil];

如果您要展示导航控制器,请添加导航控制器的视图而不是其顶视图控制器.

If you are presenting a navigation controller than add the navigation controller's view instead of its top view controller.

这篇关于AppDelegate 中的presentViewController 与iOS8 中的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:35