iphone - 自动旋转动态 UIViewcontroller

标签 iphone ios objective-c ipad uiviewcontroller

我有一个场景,我动态创建 UIViewcontrollers 并在其顶部添加 UIView 并将其推送到导航堆栈。这就是我创建 View Controller

的方式
UIViewController *vc = [UIViewController new];
[vc.view addSubView:customView];
[self.navigationController pushViewController vc];

在设备上运行我的应用程序时,我的 View 不会自动旋转。 (如果 VC 有一个实现文件,我会在 shouldAutorotate 中返回 YES 以使其工作。) 任何指示/帮助表示赞赏。

根据乔治的回复进行编辑:

George 的代码完美适用于 ios6 及以上版本。 supportedInterfaceOrientations API 已可用于 ios6.0+,正在寻找 ios4.3+ 的常规修复 谢谢..

最佳答案

如果您的导航 Controller 是 Root View Controller ,请将此类别添加到您创建它的位置,如果没有帮助,请添加到必须旋转的 View Controller

@implementation UINavigationController(Rotate)

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;    
}

@end

也可能是您忘记添加应用程序委托(delegate)

- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskAll;
}

编辑:

对于 iOS 5,您只需将此方法添加到所需的 View Controller 中。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

关于iphone - 自动旋转动态 UIViewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16333883/

相关文章:

ios - Xcode 7 找不到名为的 Storyboard

ios - 单击“已终止”状态下的 Firebase 推送通知时应用程序会卡住

iOS7 - TableView 标题中的多行文本?

iphone - “@public” 在 Objective-C 中是什么意思?

iphone内存管理奇怪的问题

iphone - 如何使用 json 将更新的数据发送到 iphone 中的服务器?

iphone - iOS : detect UIWebView reaching the top or bottom

ios - 上传 ipa 文件的 Crashlytics 不会上传 DSYM 文件

ios - 根据预期的字符创建字符串

iphone - 如何确定和解释 CGImage 的像素格式