我正在编写一个包含 UIViewController
(和 Storyboard)的模块,它可以被其他包装程序调用,所以我不能强制使用特定的 UINavigationController
的子类, 但它可以被 UINavigationController
使用。
在这种情况下,如何更改 ViewController
的方向?此外,只有一个 UIViewController
应该以编程方式更改方向。
我尝试使用 UINavigationControllerDelegate
但它没有被调用。 (我尝试在 init
和 viewDidLoad
上设置委托(delegate),但都没有用)
没有其他方法可以解决这个问题吗?
任何帮助将不胜感激。
最佳答案
在 ViewController 的 viewDidAppear
方法中设置:
横向:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
或
对于肖像:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
关于ios - 在不继承 UINavigationController 的情况下以编程方式更改 ViewController 的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37255035/