1.强制横屏模式,百度上找到很多方法,但是真正能用到项目上的却少之又少,有的是iOS版本太低的时候出的,过时了;有的方法被Apple官方私有化了。
2.开发工具设置
3.代码实现的两种方法
(1) 此方法已经被Apple官方私有化,不能通过审核,但是用来实现简易测试非常方便
1 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
(2)直接书写会出现报错,需要巧妙的转化绕过
1 if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { 2 [[UIDevice currentDevice] performSelector:@selector(setOrientation:)withObject:(id)UIInterfaceOrientationLandscapeRight]; 3 }
==>>转化后
1 if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { 2 SEL selector = NSSelectorFromString(@"setOrientation:"); 3 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; 4 [invocation setSelector:selector]; 5 [invocation setTarget:[UIDevice currentDevice]]; 6 int val = UIInterfaceOrientationLandscapeRight; 7 [invocation setArgument:&val atIndex:2]; 8 [invocation invoke]; 9 }
(3)关于NSInvocation有待进一步学习补充
时间: 2024-10-01 02:48:33