美文网首页
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]终极横竖屏切换解决方案

    [iOS]终极横竖屏切换解决方案 [iOS]终极横竖屏切换解决方案

  • JS 与 IOS 交互-横竖屏切换

    IOS 设备横竖屏情况 一般情形 所有界面都支持横竖屏切换如果App的所有切面都要支持横竖屏的切换,那只需要勾选【...

  • iOS 16强制切换横竖屏失效解决

    ios16切换横竖屏代码 注意:1.ios16 开始 UIDeviceOrientationDidChangeNo...

  • 跳转自动横屏

    iOS 知识小集(横竖屏切换) 转载自 http://www.cocoachina.com/ios/2016072...

  • IOS 横竖屏

    //iOS规定不允许强制用代码切换横竖屏 if([[UIDevicecurrentDevice]respondsT...

  • iOS16适配:APP切换横竖屏问题

    iOS16之前切换横竖屏使用的是UIDevice的setValue:forKey:方法进行切换。但在iOS16后不...

  • iOS 横竖屏切换

    AppDelegate.h @property(nonatomic,assign)BOOL isAllowRota...

  • iOS 横竖屏切换

    1、打开横竖屏开关 2、因为屏幕翻转后width和height是相反的 github地址:https://gith...

  • iOS 横竖屏切换

    iOS 中横竖屏切换的功能,在开发iOS app中总能遇到。以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰...

  • iOS 横竖屏切换

    本文只针对单个界面横竖屏界面 1.首先在TARGETS中将横竖屏勾选上(不用勾选貌似也可以,只不过需要在AppDe...

网友评论

      本文标题:iOS 横竖屏切换

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