首页 文章

启用iPhone界面方向

提问于
浏览
4

我试图让我的应用程序在设备本身旋转时旋转界面,但我无法做到正确 . 我在plist info文件中添加了支持的接口,并为shouldRotateToInterfaceOrientation返回yes .

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
        return YES;  
    } else {  
        return NO;  
    }  
}

这是如何实现轮换的?
请帮忙!

4 回答

  • 1

    也许尝试编辑info.plist并在那里添加您支持的方向?

    选择项目 - >选择目标 - >信息 - >支持的界面方向,然后单击加号4次以支持这些方向:

    Item 0   Landscape (left home button)
    Item 1   Landscape (right home button)
    Item 2   Portrait (top home button)
    Item 3   Portrait (bottom home button)
    

    希望能帮助到你!

  • 0

    确保已将 shouldRotateToInterfaceOrientation 添加到要支持不同方向的视图控制器 . 它不会进入app委托 .

  • 0

    如果您使用标准UI元素,支持方向是直截了当的,因此,假设情况如此,您就是在正确的轨道上 .

    如果您正在使用UITabController,则所有视图必须支持相同的方向,否则默认为最小(例如Portrait),我相信 .

    此外,如果您正在为视图使用NIB,请确保在Interface Builder中配置视图时选中了“自动调整子视图” .

  • 0

    如果你使用 UITabBarController ,那么你'll need to call it'的子视图' shouldAutoratateToInterfaceOrientation .

    假设您有两个选项卡,请尝试将以下两行添加到使用 UITabViewController 的类中的方法 shouldAutorotateToInterfaceOrientation .

    [[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    [[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    

    当然"tabBarController"必须通过IB链接到XIB文件中的 UITabBarController .

    谢谢,

相关问题