ios - 强制 View Controller 仅纵向

标签 ios iphone xcode rotation

在我的应用程序中,我试图强制 View Controller 只能是纵向的。我正在使用下面的代码,但实际上没有发生任何事情。我仍然能够像纵向一样看到横向屏幕吗?

我在项目设置中启用了横向(左/右)、纵向。

我做错了什么?

ViewController.m

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

最佳答案

如果您的 VC 嵌入在导航或标签栏 Controller 中,您需要在该 Controller 上创建一个类别。这是一个允许导航 Controller 以各种方式旋转的示例:

#import "UINavigationController+RotationAll.h"

@implementation UINavigationController (RotationAll)

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

@end

关于ios - 强制 View Controller 仅纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26205269/

相关文章:

iphone - Localizable.strings 编译了两次?

xcode - iOS 8 Swift Xcode 6 - 设置顶部导航栏 bg 颜色和高度

ios - 快速登录

ios - 如何更改 MFMessageComposeViewController 的导航栏颜色?

iphone - NSString initWithData 在额外的引号中返回字符串值,如何解决?

ios - fatal error : unexpectedly found nil while unwrapping an Optional value on performing segue

ios - 从应用程序委托(delegate)路由到特定的 View Controller 。 swift

ios - 根据 bool 值进入不同的 View Controller

iphone - 滚动 TableView 时自定义标签值消失

iphone - 在 UICollectionViewCell 中添加分隔符,就像在 UITableViewCell 中添加分隔符一样