查看另一个视图控制器而不显示iOS 8中的第一个 [英] Segueing to another view controller without displaying the first in iOS 8

查看:108
本文介绍了查看另一个视图控制器而不显示iOS 8中的第一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解iOS 8中的新segues。我有一个最初显示的典型登录屏幕的应用程序,如果用户已登录,则该屏幕不应显示(即使是瞬间),用户应该在我刚从初始登录屏幕看到的馈送屏幕上。

I am trying to understand the new segues in iOS 8. I have an app with a typical login screen shown initially, and if the user is logged in, that screen should not display (even for a split second) and user should be on a feed screen, which I am segueing from the initial login screen.

然而,我无法做我想做的事情。首先,我只能使用Present Modally segue,因为它是允许删除动画的唯一合适的segue。根据我在视图控制器生命周期中尝试进行切换的位置,它会在最初显示登录屏幕后瞬间消失,或者根本不消失。

However, I am not able to do what I want. First of all, I can only use Present Modally segue, as it's the only appropriate segue that allows removing animation. Depending where I try to segue in view controller lifecycle, it either segues after initially displaying the login screen for a split second, or doesn't segue at all.

我是运气不佳 viewDidAppear:因为它会在显示初始视图控制器后始终执行。

I am out of luck with viewDidAppear: because it will always get executed after the initial view controller is displayed.

我是查看 viewDidLoad viewWillAppear:但我得到了这两个(没有任何反应):

I am looking into viewDidLoad and viewWillAppear: but I get this on both (and nothing happens):

Warning: Attempt to present <UITabBarController: 0x12c617920> on <ViewController: 0x12c610590> whose view is not in the window hierarchy!

如何在不显示初始视图控制器的情况下显示另一个视图控制器,即使是一瞬间? / p>

How can I display another view controller without displaying the initial view controller, even for a split second?

推荐答案

我已经开发了超过50个具有更多UI的应用程序,我可能会喜欢。一开始,我也用这种方式做了UI - 首先登录控制器,然后做seque,删除登录控制器..问题是,如果导航树变得越来越复杂,以root用户身份登录控制器开始出现严重问题。

I've developed well over 50 applications with more UI that I would probably like to. At the beginning, I also did the UI this way - have login controller first, then do seque, remove login controller.. The problem is that if your navigation tree grows more complicated, having login controller as your root starts to present serious issues.

UI Dispatcher

所以我现在使用的是拥有最多使用视图控制器作为我的根(在你的情况下,它将是feed - 但它也可以是TabBarVC,导航控制器等),并且登录控制器作为模态视图,无论如何都没有连接到该导航链。然后,我有Singleton控制应用程序中的UI流程(如果你有更多的项目有多个故事板,我建议你这样做)。

So what I am using now is to have my most used view controller as my root (in your case, that would be feed - but it also can be TabBarVC, navigation controller etc.), and login controller as modal view that is not connected to that navigation chain by any means. Then, I have Singleton that controls UI flow in the application (if you have bigger projects with multiple storyboards, I suggest you do that).

单例的作用是在应用程序启动时,如果它应该显示登录表单,它会检查初始条件,如果是,则从storyboard获取它(使用Storyboard ID) +将其表示为模态(不是动画)。这样,登录在第一次绘制时始终可见,但如果您不想要则不必。您也不必更改导航树/初始视图控制器。

What the singleton does is that on application start, it checks for initial condition if it should present login form, and if yes it grabs it from storyboard (using Storyboard ID) + presents it as modal (not animate). This way, login is always visible on the first draw, but it does not have to if you don't want. You also don't have to change navigation tree / initial view controller.

要从故事板获取控制器,您可以使用以下内容:

To get controller from storyboard, you can use something like this:

// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
// MARK: - Login

func showLoginIfNeededAnimated(animated : Bool, completion : (() -> Void)?) {

    // Show login if user is not logged-in, for example
    if loginShouldAppearCondition {

        // Instantiate login VC from storyboard
        let storyboard : UIStoryboard = UIStoryboard(name: APPLICATION_UI_STORYBOARD_NAME_IPHONE_MAIN_FLOW, bundle: NSBundle.mainBundle())
        let loginVC : LoginVC = storyboard.instantiateViewControllerWithIdentifier(STORYBOARD_NAME_LOGIN) as! LoginVC

        // Present it
        self.baseController.presentViewController(baseNC, animated: animated, completion: completion)

        *Note - keep reference for login because of ARC!
    }
}

我注意到Facebook使用类似的东西应用程序,虽然我不能确定它们的实现(我觉得我喜欢它,因为他们如何做动画)。

I've noticed that Facebook uses something similar in their application, though I can't be sure about their implementation (I just seems to me like it due to way how they do animations).

说到动画,你可以说它没有为你提供推动画 - 嗯,如果你愿意,你可以随时自己编写,但你也可以创造更多更好的效果。有关该主题的精彩教程以及此处),因此您可以查看它以了解有趣的内容,并可能使您的应用程序更好。

Speaking of the animation, you can say that it does not provide you with push animation - well, you can always write your own if you wish to, but you can also create much more fancier effects. There is great tutorial on that topic (and also here), so you can check it to learn something interesting and possibly make your application better.

希望它对您有所帮助,如果您有任何疑问,请询问!祝你好运:)

Hope it helps you and if you have any questions, just ask! I wish you good luck :)

这篇关于查看另一个视图控制器而不显示iOS 8中的第一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆