iOS 横竖屏切换

AppDelegate.h

@property(nonatomic,assign)BOOL isAllowRotation;

AppDelegate.m

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window

{

    if (self.isAllowRotation == YES) {//横屏

        return UIInterfaceOrientationMaskLandscape;

    }else{//竖屏

        return UIInterfaceOrientationMaskPortrait;

    }

}

需要旋转的界面添加

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

    //允许转成横屏

    appDelegate.isAllowRotation = YES;

    NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];

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

    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS 中横竖屏切换的功能,在开发iOS app中总能遇到。以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰...
    零度_不结冰阅读 6,607评论 0 0
  • 网上关于横竖屏切换的资料很多,但是很容易踩到坑,不是屏幕不旋转,就是屏幕旋转后没有状态栏等,在写的小demo里屏幕...
    凌云01阅读 3,547评论 0 0
  • 进入正文前先认识几个概念 portrait 竖屏(Home键在下边) upside down 竖屏(Home键在上...
    hallfrita阅读 5,370评论 0 2
  • 尼尔·波兹曼把印刷机统治思想的那个时期叫做“阐释年代”。他认为所有成熟话语所拥有的特征,都被偏爱阐释的印刷术发扬光...
    无向宇阅读 3,328评论 0 0
  • 最近莱特币的大涨,吸引了众多目光,那我们就来探讨下莱特币大涨的原因有哪 些: 1、 受众广:从全球范围来看,莱特币...
    没什么可写的阅读 3,514评论 0 0