iOS8-导航控制器-停止旋转
我有一个iOS8-导航控制器-停止旋转,ios,objective-c,uiviewcontroller,uinavigationcontroller,screen-rotation,Ios,Objective C,Uiviewcontroller,Uinavigationcontroller,Screen Rotation,我有一个UIViewController,它位于UINavigationController的下游。我需要锁定这个vc,使它始终在纵向方向,永远不会旋转。我试过很多方法,但都不管用。现在,我正在子类化UINavigationController,如下所示: #import "CustomNavigationController.h" @interface CustomNavigationController () @end @implementation CustomNavigationC
UIViewController
,它位于UINavigationController
的下游。我需要锁定这个vc,使它始终在纵向方向,永远不会旋转。我试过很多方法,但都不管用。现在,我正在子类化UINavigationController
,如下所示:
#import "CustomNavigationController.h"
@interface CustomNavigationController ()
@end
@implementation CustomNavigationController
-(NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
NSLog(@"here");
return navigationController.topViewController.supportedInterfaceOrientations;
}
- (BOOL)shouldAutorotate {return NO;}
@end
然后在我的UIViewController
中,我有以下代码:
-(NSUInteger)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {return UIInterfaceOrientationMaskPortrait;}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {return UIInterfaceOrientationPortrait;}
- (BOOL)shouldAutorotate {return NO;}
但这不起作用。只要我旋转设备(模拟器),屏幕就会旋转,一切都不正常。另外,nav控制器中的log语句从未生成过,所以我甚至没有开始讨论这个方法
我不打算在这里支持景观模式,因为布局的性质是这样的,它没有意义
有人能看出我做错了什么吗?谢谢。您是否在项目设置中设置了纵向模式?是的。纵向、横向、左侧和右侧。问题不在于它不会进入肖像。只是它不会停留在肖像上。