需求:
让push的ViewController界面强制横屏
一、配置
image.png二、添加强制横屏方法
pragma mark -- 强制转换横屏
-
(void)orientationToPortrait:(UIInterfaceOrientation)orientation {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = orientation;
[invocation setArgument:&val atIndex:2];//前两个参数已被target和selector占用
[invocation invoke];
}
三、在需要跳转的方法中调用上述方法,令其转换屏幕
[self orientationToPortrait:UIInterfaceOrientationLandscapeLeft];
- 1
四、返回竖屏的方法中调用
[self orientationToPortrait:UIInterfaceOrientationPortrait];
网友评论