美文网首页
开发 Tips

开发 Tips

作者: 寒咯 | 来源:发表于2016-09-19 13:50 被阅读17次
    1.强制转屏
        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                  = orientation;
        // 从2开始是因为0 1 两个参数已经被selector和target占用
        [invocation setArgument:&val atIndex:2];
        [invocation invoke];
       //重点是这句
        [UIViewController attemptRotationToDeviceOrientation];
    }
    
    • 官方文档对 attemptRotationToDeviceOrientation 的描述是:
      Some view controllers may want to use app-specific conditions to determine what interface orientations are supported. If your view controller does this, when those conditions change, your app should call this class method. The system immediately attempts to rotate to the new orientation.

    相关文章

      网友评论

          本文标题:开发 Tips

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