iOS 横竖屏切换的方法

//旋转方向

- (void)interfaceOrientation:(UIInterfaceOrientation)orientation

{

    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;

        

        [invocation setArgument:&val atIndex:2];

        [invocation invoke];

    }

    if (orientation == UIInterfaceOrientationLandscapeRight||orientation == UIInterfaceOrientationLandscapeLeft) {

        // 设置横屏

    } else if (orientation == UIInterfaceOrientationPortrait) {

        // 设置竖屏

    }else if (orientation == UIInterfaceOrientationPortraitUpsideDown){

        //

    }

}

猜你喜欢

转载自blog.csdn.net/ForeverMyheart/article/details/113887115