[iOS] 横竖屏转换

强制变成横屏(ARC下也可使用)

if ( [[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)] ) {
    SEL selector = NSSelectorFromString(@"setOrientation:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setTarget:[UIDevice currentDevice]];
    int val = UIInterfaceOrientationLandscapeRight;
    [invocation setArgument:&val atIndex:2];
    [invocation invoke];
}

强制变回竖屏(ARC下也可使用)

if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    SEL selector = NSSelectorFromString(@"setOrientation:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setTarget:[UIDevice currentDevice]];
    int val =UIInterfaceOrientationPortrait;
    [invocation setArgument:&val atIndex:2];
    [invocation invoke];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 之前写过进入从A页面进入B页面,B页面直接进入就是横屏的情况,使用一个方法就可以了,但是昨天又遇到这个需求的时候又...
    小镜子呀阅读 436评论 0 0
  • 概述 写代码就是在不断填坑的过程中慢慢成长,程序员哪有不遇坑的呢? 这篇文章来谈谈iOS中横竖屏切换的一些坑,横竖...
    jumpingfrog0阅读 11,482评论 6 21
  • iOS 中横竖屏切换的功能,在开发iOS app中总能遇到。以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰...
    零度_不结冰阅读 2,298评论 0 0
  • 这城市灯火璀璨,却没有一盏为我而开,但那又如何,即便无粥可温,我也要有最灿烂的模样,好好努力的活着就是最大的幸运。...
    夏心儿阅读 460评论 0 0
  • 我的作业,简直就是微社里垫底的那个,其实不用简直,就用一直两字合适。 实在是在打开简书时,对着屏幕发呆。而这一天过...
    lindacui阅读 195评论 1 0

友情链接更多精彩内容