@property(nonatomic,assign)BOOL isRotationRight;//是否横屏
(AppDelegate *)appDelegate;
//设置横竖屏
- (void)setLandscapeRight:(BOOL)isRight;
3、AppDelegate.m实现
{
self.isRotationRight = isRight;//(以上2行代码,可以理解为打开横屏开关)
if (self.isRotationRight) {
NSnumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}else{
NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}
}
#pragma mark - 横竖屏管理
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
if (self.isRotationRight == YES) {
return UIInterfaceOrientationMaskLandscapeRight;
}else{
return (UIInterfaceOrientationMaskPortrait);
}
}
4、哪个需要横屏调用:
[[AppDelegate appDelegate] setLandscapeRight:YES];
5、不需要横屏调用:
[[AppDelegate appDelegate] setLandscapeRight:NO];
Demo 地址:
https://github.com/HuiTongZhiYuan/TestOrientation
,
Copyright © 2008-2022 秒下下载站
m.down10s.com .All Rights Reserved