美文网首页iOS在路上
iOS点击按钮后实现横屏,IOS点击横屏,IOS横屏播放

iOS点击按钮后实现横屏,IOS点击横屏,IOS横屏播放

作者: ing_69c7 | 来源:发表于2020-04-15 09:54 被阅读0次

在AppDelegate.h中定义这两个属性

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (nonatomic, assign) BOOL allowRotation;//允许旋转

@property (nonatomic, assign) BOOL rightRotation;//右侧旋转

@end

在AppDelegate.m中添加下方代码

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

    if (self.allowRotation) {

        return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;

    }elseif(self.rightRotation) {

        return UIInterfaceOrientationMaskLandscapeRight;

    }

    return UIInterfaceOrientationMaskPortrait;

}

在想要横屏时

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

        appdelegate.rightRotation=YES;

        [appdelegateapplication:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];

        //强制翻转屏幕,Home键在右边。

        [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) forKey:@"orientation"];

        //刷新

        [UIViewController attemptRotationToDeviceOrientation];

竖屏时

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

        appdelegate.rightRotation=NO;

        [appdelegateapplication:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];

       //强制翻转屏幕

       [[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];

       //刷新

       [UIViewController attemptRotationToDeviceOrientation];

不需要选择支持左右旋转

相关文章

网友评论

    本文标题:iOS点击按钮后实现横屏,IOS点击横屏,IOS横屏播放

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