美文网首页
[iOS] 横竖屏转换

[iOS] 横竖屏转换

作者: 两年如歌 | 来源:发表于2016-03-29 19:41 被阅读252次

    强制变成横屏(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];
    }
    

    相关文章

      网友评论

          本文标题:[iOS] 横竖屏转换

          本文链接:https://www.haomeiwen.com/subject/fzyslttx.html