嵌入在导航控制器中的登录视图控制器必须是纵向的。其他视图控制器的 push 可以旋转。场景:如果登录后我旋转子视图控制器,然后注销登录视图控制器出现在横向中。
logincontroller(portrait)->rotated device->childcontroller(landscape)->back->logincontroller(landscape)
当我回来时,我希望登录控制器是纵向的。
在你的登录 ViewController 中输入这两个方法
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait |
UIInterfaceOrientationMaskPortraitUpsideDown);
}
和
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationLandscapeRight |
UIInterfaceOrientationLandscapeLeft);
}
在您的孩子控制器中
在你的登录 ViewController 中输入这两个方法
(BOOL)shouldAutorotate { return YES;
}
(NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown); }
和
(BOOL)shouldAutorotate { return YES;
}
(NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationLandscapeLeft); }
在您的孩子控制器中
需要添加类别自动旋转子类导航控制器,该控制器将调用 topcontroller shouldautorotate 并支持界面方向。
#import "UINavigationController+Autorotation.h"
@implementation UINavigationController (Autorotation)
-(BOOL)shouldAutorotate
{
for (UIViewController * viewController in self.viewControllers) {
if (![viewController isEqual:self.topViewController]) {
[viewController shouldAutorotate];
}
}
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
for (UIViewController * viewController in self.viewControllers) {
if (![viewController isEqual:self.topViewController]) {
[viewController supportedInterfaceOrientations];
}
}
return [self.topViewController supportedInterfaceOrientations];
}