iOS 强制横竖屏

强制横屏

 NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
 [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
 NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
 [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];

强制竖屏

NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown]; [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];

⚠️

在执行上述方法时要重写controller的一下方法

//1,支持旋转
-(BOOL)shouldAutorotate{
   return YES;
}
//2,支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
   //所有方向
   return UIInterfaceOrientationMaskAllButUpsideDown;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在iOS软件开发中,一般APP可能是需要全部横屏或者竖屏,但是有的时候会遇到这样的问题,就是我们的其中一个或者几个...
    神经骚栋阅读 1,014评论 4 11
  • 最近在修改直播项目出现的问题,需要在直播页面强制进入横屏,记录下遇到的坑,稍后会写一篇阿里云直播的文章. 程序单独...
    daihz阅读 879评论 0 3
  • 概述 写代码就是在不断填坑的过程中慢慢成长,程序员哪有不遇坑的呢? 这篇文章来谈谈iOS中横竖屏切换的一些坑,横竖...
    jumpingfrog0阅读 11,386评论 6 21
  • iOS 中横竖屏切换的功能,在开发iOS app中总能遇到。以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰...
    零度_不结冰阅读 2,243评论 0 0
  • 01 入院 18床,收拾东西,可以出院了!护士大着嗓门朝我嚷道。 今天才发现,平日里凶巴巴的护士笑起...
    家乡雪韵阅读 387评论 3 9