iOS 横竖屏切换

2018-07-02  本文已影响16人  Hanson_HSS

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

上一篇下一篇

猜你喜欢

热点阅读