app支持自动屏幕旋转的时候,横屏时,启动app的时候界面横屏的bug解决

前要

今天偶然测试我们app的我的手机默认开启了自动旋转的功能,我正好把手机横屏放着,这个时候真机测试的时候,整个UI的界面也是横屏的,很奇怪的明明UIViewController根控制器和UINavigationController导航控制器以及UITabBarController标签控制器的都设置了不支持横屏的。

UITabBarController和UINavigationController

- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.selectedViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}

UIViewControler


- (BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return  UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
问题分析

只要手机的物理方向是横屏状态的下打开app,就会出现app是横屏状态的,整个UI界面就会横屏的状态,首先猜测既然横屏的方向,那么能不能强制竖屏呢?在app的代理的入口处直接设置
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];//此方法发现还是不行,手机横屏状态下打开的话还是横屏的布局的UI界面的,后来我突然想到是不是进入app的第一个界面的控制器的影响的,我看了一下我的app打开首先进入的第一个界面,由于app首先打开会进入一个代替系统的启动页的控制器的界面,类似于启动页上面加个广告页的业务需求,每次都会先进入这个展示广告的启动页。果然只要设置这个展示广告的页面只支持竖屏,最后完美解决了。

- (BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return  UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
最终总结

最重要的打开了手机app的自动旋转的功能,否则你就是横屏的情况下也不会有任何作用,因为系统直接把你的手机固定为竖屏。
1.app的代理方法中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    //防止手机横屏时出现的界面横屏布局
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];//此方法
}

2.app打开时,第一个展示的控制器一定要强制只支持竖屏,不支持自动旋转。

最后完美解决,自动旋转打开下,横屏手机打开app,界面出现横屏的情况。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值