代码之家  ›  专栏  ›  技术社区  ›  Lio

旋转UIView-未调用willRotateToInterfaceOrientation

  •  4
  • Lio  · 技术社区  · 17 年前

    我正在尝试自动旋转视图,我在这里解释了相同的问题: willRotateToInterfaceOrientation not being called .

    即使我实现了 shouldAutorotateToInterfaceOrientation UIViewController willRotateToInterfaceOrientation

    也许有人能告诉我我错过了什么。我有以下视图控制器结构(我希望这足够清楚):

    NavigationController (Programatically) 
         -with root > TabBarController (Programatically) 
                      -with tab item > NavigationController (Programatically)
                                       -with root > UITableViewController (a Subclass) 
                                                    -pushed to navigator controller > UIViewController (a Subclass).
    

    我希望有人能帮助我。提前谢谢!

    2 回复  |  直到 9 年前
        1
  •  1
  •   Volodymyr B.    15 年前

    您可以尝试通过rootviewcontroller将控制器(NavigationController)插入到窗口。

    编辑

    作品:

    // custom controller
        TestController *t = [[TestController alloc] init];
    
        // navigaton
        UINavigationController *controllerinsertIntoTab = [[UINavigationController alloc] initWithRootViewController:t];
    
        // tab bar
        UITabBarController *tabbarController = [[UITabBarController alloc] init];
        [tabbarController addChildViewController:controllerinsertIntoTab];
    
        // first navigation
        UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:tabbarController];
    
        [self.window setRootViewController:controller];
    

    特别为你准备的 https://github.com/sakrist/TestControllers

    我希望这会有帮助

        2
  •  0
  •   Suran    13 年前

    willAutoRotateToInterfaceOrientation

    self.viewController 是您的根视图控制器和 childViewController 是要在其中获取自动旋转回调的视图控制器,请添加以下代码行;

    [self.viewController addChildViewController:childViewController];

    实际上,将作为子视图控制器添加到任何获取旋转回调的视图控制器也会起作用。

    希望能有帮助。

    推荐文章