【发布时间】:2017-08-22 06:30:19
【问题描述】:
我想在几个 UIViewcontroller 中锁定方向
1) 登录视图(仅支持纵向) UIViewcontroller 具有登录按钮
2)在登录按钮上,我从情节提要中调用 UITabbarController,有 3 个选项卡,所有选项卡都嵌入 UINavigationControllers。(Tab1,Tab2,Tab3)
3) 在 Tab1 上(支持横向和纵向)具有按钮 button1,我从中推送 UIViewcontroller 演示(仅支持纵向)。如下所示
Demo *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Demo"];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
Demo 已成功加载,但我想将其旋转锁定为纵向,因此我创建了 UINavigationController 类别,但它仍在旋转。
#import <UIKit/UIKit.h>
@interface UINavigationController (Orientation)
@end
//==========
#import "UINavigationController+Orientation.h"
@implementation UINavigationController (Orientation)
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortraitUpsideDown;;
}
@end
//------- 在我的演示 uiviewcontroller 中,但在代码下方,但它从未调用过--------
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
我看了很多帖子,但都没有帮助,请帮我看看我该怎么做?
【问题讨论】:
标签: ios objective-c iphone uiviewcontroller uiinterfaceorientation