【问题标题】:Rotating UIView - willRotateToInterfaceOrientation not being called旋转 UIView - willRotateToInterfaceOrientation 未被调用
【发布时间】:2010-12-07 16:02:08
【问题描述】:

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

即使我实现了shouldAutorotateToInterfaceOrientation 并返回了YES,但在我实现的每个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).

我希望有人可以帮助我。提前致谢!

【问题讨论】:

  • 你找到答案了吗?我遇到了同样的问题。
  • 这似乎是一个基本的 iOS SDK 问题。

标签: iphone ios uiview uiviewcontroller


【解决方案1】:

如果您没有在任何视图控制器中接收到 willAutoRotateToInterfaceOrientation 的回调,请将视图控制器添加为您的根视图控制器的子视图控制器。

例如;假设self.viewController 是您的根视图控制器,childViewController 是您想要在其中获得自动旋转回调的视图控制器,添加以下代码行;

[self.viewController addChildViewController:childViewController];

实际上,将作为子视图控制器添加到任何获得旋转回调的视图控制器也可以。

希望对你有帮助。

【讨论】:

    【解决方案2】:

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

    如果不适合你,请使用通知 UIApplicationWillChangeStatusBarOrientationNotification

    编辑

    作品:

    // 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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多