我的项目有UITabbar,UınavigationBar和UIViewContoller。
-UITabbar
—UINavigationController
—UIViewController
问题:我怎么能做横向禁用一个viewController?我想只是纵向视图,但只想一个视图。
答案 0 :(得分:4)
<击> disable autorotate on a single UIViewController in iOS6 击>
<击>将此添加到您的应用代理
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[window.rootViewController presentedViewController] isKindOfClass:[YourViewController class]])
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskAllButUpsideDown;
}
击> <击> 撞击> 编辑2
我最近发现了这一点,它一直对我很有用。将此代码添加到视图控制器
- (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"];
}