gpt4 book ai didi

ios - 在不继承 UINavigationController 的情况下以编程方式更改 ViewController 的方向

转载 作者:行者123 更新时间:2023-11-29 12:00:27 25 4
gpt4 key购买 nike

我正在编写一个包含 UIViewController(和 Storyboard)的模块,它可以被其他包装程序调用,所以我不能强制使用特定的 UINavigationController 的子类, 但它可以被 UINavigationController 使用。
在这种情况下,如何更改 ViewController 的方向?此外,只有一个 UIViewController 应该以编程方式更改方向。
我尝试使用 UINavigationControllerDelegate 但它没有被调用。 (我尝试在 initviewDidLoad 上设置委托(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com