我的项目有 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/