【问题标题】:UIWindow rootviewcontroller - wrong orientationUIWindow rootviewcontroller - 方向错误
【发布时间】:2012-10-08 12:37:03
【问题描述】:

我正在开发一个 iPad 应用程序,如果用户输入密码,用户就可以(在某些情况下)打开该应用程序。 因此我需要像 LoginViewController 这样的东西。但首先,让我们处理常见的情况,即应用只需要显示 HomeViewController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
    //...
    self.controllerHomeView = [[HomeViewController alloc] initWithNibName:@"HomeView" bundle:nil];
    self.controllerHomeView.showInitialGuide = isFirstLaunch;
    self.window.rootViewController = controllerHomeView;
    [self.window makeKeyAndVisible];
    //..
}

但是,就像我之前说的,有些用户可能已经定义了密码,如果是这样,我们需要显示一个登录屏幕。这就是我为启用此类功能所做的:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //---
    if(isAppPinSecured && !loginIsAlreadyDisplaying) {
        LoginBackgroundViewController *controllerLoginBG = [[LoginBackgroundViewController alloc] initWithNibName:@"LoginBackgroundView" bundle:nil];
        self.appPinInputBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Landscape@2x~ipad.png"]];
        self.appPinInputBG.frame = CGRectMake(0, 0, 1024, 748);
        self.appPinInputBG.userInteractionEnabled = YES;
        [controllerLoginBG.view addSubview:self.appPinInputBG];
        //present new root = background
        self.window.rootViewController = controllerLoginBG;
        //...
    }
}

我正在做的是将根视图控制器更改为 LoginViewController,如果用户输入正确的密码,则从 LoginViewController 更改回 HomeViewController

到目前为止一切正常,除了方向。如果当前界面方向未知,因为 iPad 例如放在桌子上时,LoginViewController 方向是 LandscapeRight 而不是 HomeViewController 中的方向(LandscapeLeft)。 如果将 iPad 握在手中,它可以正常工作,但否则就不行。

关于如何解决该问题的任何建议?我确实在 plist 文件(横向左)中设置了我的应用程序方向。我确实在 Home- 和 LoginViewController 中都使用 UIInterfaceOrientationIsLandscape(...) 实现了 shouldAutorotate。

提前致谢!

【问题讨论】:

    标签: ios ipad uiviewcontroller uiwindow


    【解决方案1】:

    啊,问题是,我试图在调用 viewDidAppear 之前以模态方式推送视图控制器 -> 你永远不应该这样做......

    由于这个错误而更改了我的代码后,它就像一个魅力

    【讨论】:

      【解决方案2】:

      我认为正在发生的事情是在初始根控制器上设置了首选方向 - 当您将其切换出来时,它没有设置。

      我建议您考虑始终将 HomeViewController 设为根控制器。并且不要切换根控制器,而是推送 LoginViewController(如果您希望它立即显示,则不要动画):

       [self.navigationController pushViewController:controllerLoginBG animated:NO]
      

      这样您就可以执行诸如注销和弹出到 HomeViewController 之类的操作。它还将使您的视图控制器导航保持一致。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-16
        • 2013-03-17
        • 1970-01-01
        • 2011-12-24
        • 2018-06-15
        • 1970-01-01
        • 2012-01-02
        相关资源
        最近更新 更多