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

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

@interface AppDelegate : UIResponder

@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横屏播放_第1张图片

你可能感兴趣的:(iOS点击按钮后实现横屏,IOS点击横屏,IOS横屏播放)