美文网首页JC专题
iOS编程, 点击变横屏(竖屏)

iOS编程, 点击变横屏(竖屏)

作者: 霍伟健 | 来源:发表于2016-03-29 21:03 被阅读255次

横屏:


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

竖屏:


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/tupslttx.html