我有一个场景,我动态创建 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/