开发 Tips

2016-09-19  本文已影响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];
}
上一篇下一篇

猜你喜欢

热点阅读