美文网首页
强制横屏

强制横屏

作者: 一笔春秋 | 来源:发表于2018-12-10 17:49 被阅读8次

1、AppDelegate里设置属性

@property(nonatomic,assign)BOOLallowLandscapeLeftRotation;//是否允许转向

2、AppDelegate里设置方法

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullableUIWindow *)window

{

    if(_allowLandscapeLeftRotation ==YES) {

        return UIInterfaceOrientationMaskLandscapeLeft;

    }else{

        return UIInterfaceOrientationMaskPortrait;

    }

}

- (void)setNewOrientation:(BOOL)isLandscapeLeft

{

    if(isLandscapeLeft) {

        NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];

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

        NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];

        [[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"];

    }

}

3、调用

AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

appDelegate.allowLandscapeLeftRotation = YES;

[appDelegate setNewOrientation:YES];

相关文章

  • iOS:强制横屏的坑

    前段时间我们播放器强制横屏,项目设置允许竖屏,在手机不锁屏状态下,手机横屏会导致播放器强制横屏的时候会导致横屏失败...

  • iOS强制横屏

    iOS强制横屏

  • 强制横屏方法

    强制横屏: 方法一: 关于强制横屏看了很多文章,首先第一个方法是invocation,这个方法可以实现横屏效果,但...

  • 强制横屏

    转载自 :http://blog.csdn.net/zhaotao0617/article/details/525...

  • 强制横屏

    -(void)landscapeAndPortraitChange{UIInterfaceOrientation ...

  • 强制横屏

    1、AppDelegate里设置属性 @property(nonatomic,assign)BOOLallowLa...

  • iOS强制横屏方法之一

    //这段代码是强制产生横屏效果,通过kvo实现//强制右横屏 可以过审核-(void)viewWillAppea...

  • 横竖屏

    需求: 让push的ViewController界面强制横屏 一、配置 二、添加强制横屏方法 pragma mar...

  • iOS 屏幕旋转控制

    /** 屏幕旋转控制 allowRotateType ==(0强制竖屏,1横竖屏,2~强制横屏 )*/ (UIIn...

  • 2021-10-21

    uni-app强制横竖屏 //强制横屏 plus.screen.lockOrientation('landscap...

网友评论

      本文标题:强制横屏

      本文链接:https://www.haomeiwen.com/subject/aosdhqtx.html