gpt4 book ai didi

ios - 我怎样才能为一个 viewController iOS 禁用横向

转载 作者:可可西里 更新时间:2023-11-01 05:40:53 24 4
gpt4 key购买 nike

我的项目有 UITabbar、UınavigationBar 和 UIViewContoller。

-UITabbar
—UINavigationController
—UIViewController

问题:我怎样才能横向禁用一个viewController?我只想纵向 View ,但只有一个 View 。

最佳答案

<罢工> disable autorotate on a single UIViewController in iOS6

<罢工>

将此添加到您的应用委托(delegate)

- (NSUInteger) application:(UIApplication *)application     supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if ([[window.rootViewController presentedViewController] isKindOfClass:[YourViewController class]])
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskAllButUpsideDown;
}

<罢工> 编辑 2

我最近发现了这一点,它对我来说效果很好。将此代码添加到您的 View Controller

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

然后在你的 viewWillAppear 添加

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

///Disable orientation changes
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}

关于ios - 我怎样才能为一个 viewController iOS 禁用横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26830458/

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