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

原文地址:http://blog.csdn.net/dream9393/article/details/75305152


需求: 
让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];
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

三、在需要跳转的方法中调用上述方法,令其转换屏幕

    [self orientationToPortrait:UIInterfaceOrientationLandscapeLeft];
  • 1

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

    [self orientationToPortrait:UIInterfaceOrientationPortrait];
  • 1

你可能感兴趣的:(IOS开发)