iOS8 - 导航控制器 - 停止旋转

时间:2015-12-17 19:47:45

标签: ios objective-c uiviewcontroller uinavigationcontroller screen-rotation

我的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;}

但这不起作用。旋转设备(模拟器)后,屏幕旋转,一切都不合适。此外,导航控制器中的日志语句永远不会生成,因此我甚至没有首先使用此方法。

我不打算在这里支持横向模式,因为布局的性质是没有意义的。

谁能看到我做错了什么?谢谢。

0 个答案:

没有答案