首页 文章

iOS首先自动旋转视图

提问于
浏览
0

我正在开发一个必须在横向和纵向工作的ios应用程序,除了一个视图,应该始终在横向 . 所以我有:

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

如果我以横向模式午餐我的应用程序,并进入此视图并旋转设备(iPad),此方法被调用并返回false,因此界面不会旋转,好东西 .

但如果我是肖像并且进入此视图,则调用此方法并返回false,但方向不会更改 . 在此上下文中,如果我将设备旋转为横向,则该方法返回true并且界面正确旋转,如果我尝试再次旋转为纵向,则此方法返回false并且界面保持在横向中 .

如何在第一次看到此视图时如何实现该功能,如果设备处于纵向状态,界面将更改为横向?

另外,我试过了

- (NSUInteger)supportedInterfaceOrientations

但它永远不会被召唤 .

提前致谢!

1 回答

  • 0

    shouldAutorotateToInterfaceOrientation: 在iOS 6.0中已折旧 . 改为覆盖 supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation 方法 .

    来自 preferredInterfaceOrientationForPresentation 上的文档

    如果视图控制器实现此方法,则在显示时,其视图将以首选方向显示(尽管稍后可以将其旋转到另一个受支持的旋转) . 如果未实现此方法,系统将使用状态栏的当前方向显示视图控制器 .

相关问题