旋转UIView - willRotateToInterfaceOrientation方法未被调用

4

我正试图自动旋转一个视图,并且我遇到了与这里解释的相同的问题:willRotateToInterfaceOrientation not being called

尽管我在每个继承了UIViewController的子类中都实现了shouldAutorotateToInterfaceOrientation并返回了YES,但willRotateToInterfaceOrientation没有被调用。

也许有人可以告诉我我漏掉了什么。 我有以下视图控制器结构(希望这足够清晰..):

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

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


你是否找到了这个问题的答案?我也遇到了相同的问题。 - rein
这似乎是一个基本的iOS SDK问题。 - Oscar
2个回答

1

您可以尝试通过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

希望对您有所帮助


0

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

例如,假设self.viewController是您的根视图控制器,而childViewController是您想要获取自动旋转回调的视图控制器,则添加以下代码行:

[self.viewController addChildViewController:childViewController];

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

希望对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接