iOS固定APP 某个界面强制横屏或者竖屏

2020-01-13  本文已影响0人  New_卡迪熊

#import "AppDelegate.h"

@property (nonatomic,assign)BOOL allowAcrolls;

添加一下方法

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

    if(self.allowAcrolls) {

        returnUIInterfaceOrientationMaskLandscapeLeft;

    }

    returnUIInterfaceOrientationMaskPortrait;

}

2.然后在需要强制转换的方法里添加以下代码:

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

           appdelegate.allowAcrolls =YES;

          [[UIApplication sharedApplication] setStatusBarHidden:YESwithAnimation:UIStatusBarAnimationNone];

           NSNumber *orientationTarget = [NSNumber numberWithInt:UIDeviceOrientationLandscapeRight];

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

这样就差不多OK了。

上一篇 下一篇

猜你喜欢

热点阅读