iphone - 原力风景 iOS 6

标签 iphone ios objective-c rotation

我希望我的应用程序中的一个 View 具有横向方向。我设法让 View 在手动旋转时保持横向,但如果设备已经是纵向的,它会保持纵向,无论其支持的方向如何(使用 supportedInterfaceOrientations 方法设置)。有没有办法让 View 自动旋转?我试过:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

但这行不通。

如有任何建议,我们将不胜感激!

最佳答案

实现此目的的一种方法是覆盖 preferredInterfaceOrientationForPresentation 但为了调用它,viewController 必须被presented(如在模态中)而不是像提到的那样被推送here :

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    NSLog(@" preferred called");
    return UIInterfaceOrientationPortrait;
}

为了在 UINavigationController 中显示您的 viewController,请使用:

UINavigationController *presentedNavController = [[UINavigationController alloc] initWithRootViewController:protraitViewController];

[self presentViewController:presentedNavController animated:YES completion:nil];

要使 UINavigationController 尊重您当前 viewController 的方向首选项,请使用这个简单的 category而不是子类化。

此外,这 part阅读 Apple 文档有助于更好地理解 iOS 方向处理。

关于iphone - 原力风景 iOS 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16132965/

相关文章:

ios - Appstore发布应用的神奇记录,核心数据迁移

iphone - 使用更新的配置文件重建 IPA 文件

iphone - JSON 到具有关系的核心数据

objective-c - 我可以通过仅在一个集合中更改存储在两个集合中的对象来更新该对象吗?

iphone - _OBJC_CLASS_$_RscMgr 链接器错误

ios - 每个 iOS 应用程序在设备上都有自己的单个钥匙串(keychain)吗?

ios - UIPopoverController backgroundColor 在 iOS 8 上旋转后返回默认值

ios - 如何以编程方式将不同单元格的不同图像添加到 tableView (Swift 3)

objective-c - 在 iPhone 应用程序中使用 UiWebView(用于支付)会被拒绝吗?应用程序是一种网络服务

ios - 在collectionView中加载图像