美文网首页
iOS 横竖屏切换

iOS 横竖屏切换

作者: Hanson_HSS | 来源:发表于2018-07-02 14:58 被阅读16次

    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 横竖屏切换

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