OGeek|极客世界-中国程序员成长平台

标题: ios - 当 View 从纵向更改为横向时,方向不会改变 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 22:56
标题: ios - 当 View 从纵向更改为横向时,方向不会改变

我有仅纵向的菜单和可以是纵向或横向的详细 View (带有 UIWebView)。

当我进入详细 View 并旋转设备横向并以这种方式从该屏幕返回到仅应为纵向的菜单时,菜单处于横向(以及状态栏和导航栏)。

有没有办法避免这种情况并强制将屏幕旋转到所需(支持的)方向?



Best Answer-推荐答案


@kkumpavat 提出的解决方案对我不起作用,或者不够清楚,我无法理解。我做了更多搜索并找到了使用的解决方案:

    // http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation
    // http://openradar.appspot.com/radar?id=697
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                   withObject:UIInterfaceOrientationPortrait];

但这会产生烦人的警告,我已将其替换为:

//force update of screen orientation
if (self.interfaceOrientation != [self preferredInterfaceOrientationForPresentation]) {
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: [self preferredInterfaceOrientationForPresentation]]
                                forKey"orientation"];
}

从 NavigationController 的 viewDidAppear 调用。

关于ios - 当 View 从纵向更改为横向时,方向不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24141449/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4