iOS 某一个界面实现强制横屏

需求:
让push的ViewController界面强制横屏

一、配置
iOS 某一个界面实现强制横屏_第1张图片

二、添加强制横屏方法

#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];

四、返回竖屏的方法中调用

    [self orientationToPortrait:UIInterfaceOrientationPortrait];

你可能感兴趣的:(oc基础)