导航控制器中嵌入的登录视图控制器必须只是纵向。 其他视图控制器的推动可以旋转。 场景: 如果在登录后我旋转子视图控制器,然后注销登录视图控制器出现在横向。
logincontroller(portrait) - > rotate device-> childcontroller(landscape) - > back-> logincontroller(landscape)
我希望登录控制器在我回来时是肖像。
答案 0 :(得分:1)
在登录ViewController中输入这两个方法
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskPortrait |
UIInterfaceOrientationMaskPortraitUpsideDown);
}
和
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationLandscapeRight |
UIInterfaceOrientationLandscapeLeft);
}
在您的子控制器中
答案 1 :(得分:0)
在登录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];
}