iOS 横竖屏切换

AppDelegate.h

@property(nonatomic,assign)BOOL isAllowRotation;

AppDelegate.m

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window

{

    if (self.isAllowRotation == YES) {//横屏

        return UIInterfaceOrientationMaskLandscape;

    }else{//竖屏

        return UIInterfaceOrientationMaskPortrait;

    }

}

需要旋转的界面添加

AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    //允许转成横屏

    appDelegate.isAllowRotation = YES;

    NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];

    [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];

    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];

    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];

你可能感兴趣的:(iOS 横竖屏切换)