iOS设置具体页面横屏或者是竖屏

页面跳转方式:Nav push跳转方式

1.设置项目支持的旋转方向:


2.创建子类CusNavViewController继承UINavigationController

3.写一个子类CusNavigationController 继承 UINavigationController,在CusNavigationController中重写方法:shouldAutorotate 和 supportedInterfaceOrientations

@implementation CusNavViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

//支持旋转

-(BOOL)shouldAutorotate{

return [self.topViewController shouldAutorotate];

}

//支持的方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

return [self.topViewController supportedInterfaceOrientations];

}

@end

4.界面A设置支持的方向和是否可以旋转

/是否可以旋转

- (BOOL)shouldAutorotate

{

return false;

}
//支持的方向

-(UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait;

}

5.push进去的界面B 设置 方向 和 旋转

//支持的方向

-(UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskLandscapeLeft;

}

//是否可以旋转

-(BOOL)shouldAutorotate

{

return YES;

}

6.界面B设置物理设备方向:

-(void)viewWillAppear:(BOOL)animated{

NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];

[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];

NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];

[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];

}






猜你喜欢

转载自blog.csdn.net/a121267963/article/details/78332121