框架 XMHVScreen
在不同界面设置横屏或者竖屏,以及之间的切换
#继承UINavigationController新建导航栏
.m文件添加代码
// 屏幕旋转
-(BOOL)shouldAutorotate{
return self.topViewController.shouldAutorotate;
}
//支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.topViewController.supportedInterfaceOrientations;
}
此导航栏设置为根控制器
#导入头文件
#import "XMNav.h"
需要竖屏的控制器继承 XMVerticalScreenViewController
需要横屏的控制器继承 XMHorizontalScreenViewController
原理:
设置竖屏控制器
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// 设置竖向方向
[self setDirection];
}
// 设置竖向方向
- (void)setDirection{
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationMaskPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}
//支持的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
//是否可以旋转
-(BOOL)shouldAutorotate
{
return YES;
}
设置横向方向
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// 设置横向方向
[self setDirection];
}
// 设置竖横向方向
- (void)setDirection{
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}
//支持的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
//是否可以旋转
-(BOOL)shouldAutorotate
{
return YES;
}
关注微信公众号“应讯”
关注微信公众号“应讯”
网友评论