iPad屏幕适配的一些坑

1、个别界面设置不可转屏的话,刚进来的时候状态栏在哪,之后就不会变了。

- (BOOL)shouldAutorotate {
    return YES;
}

比如登录页面只支持竖屏的话,我们这样设置是有一个状态栏的问题的:

- (BOOL)shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

这样设置,刚进入界面的时候状态栏是在哪,之后转屏幕,状态栏也不会变了,一直是之前那个方向了。

最好设置支持旋转,但是Home键一直朝下,就竖屏了:

- (BOOL)shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

这样的话,状态栏和界面都是竖屏显示的。

2、项目中代码设置的转屏方向,在Device Orientation处不支持的话,就会出现闪退。

闪退信息:

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', 
reason: 'Supported orientations has no common orientation with the application, and [xxxxxx shouldAutorotate] is returning YES'
*** First throw call stack:
(0x182f12d8c 0x1820cc5ec 0x182f12c6c 0x18cb66ec4 0x18cb66848 0x18cb664e4 0x102631124 0x1026406ec 0x18cae2e38 0x18cae2240 0x18caaf65c 0x18d0dfa0c 0x18caaee4c 0x18caaece8 0x18caadb78 0x18d74372c 0x18caad268 0x18d5289b8 0x18d676ae8 0x18caacc88 0x18caac624 0x18caa965c 0x18caa93ac 0x185710470 0x185718d6c 0x103e61220 0x103e6d850 0x185744878 0x18574451c 0x185744ab8 0x182ebb404 0x182ebac2c 0x182eb879c 0x182dd8da8 0x184dbb020 0x18cdb978c 0x10263f988 0x182869fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException

比如项目中需要竖屏:

- (BOOL)shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

但是在Device Orientation处设置了只支持横屏:
这里写图片描述

这样就闪退了,报如上错误信息,提示开发者- shouldAutorotate 方法里应该返回NO。

返回NO就达不到我们想要的效果,所以,项目里都需要什么屏幕显示,就在Device Orientation处都选择上,一旦漏选,但是业务需要的话代码就会闪退。

3、属性

UIInterfaceOrientation是UIViewController的属性

UIDeviceOrientation是UIDevice的属性

在controller里取设备方向:

UIInterfaceOrientation curOrientation = self.interfaceOrientation;//iOS-iOS8

或者

UIDeviceOrientation curOrientation = [UIDevice currentDevice].orientation

4、看清这个方法的注释

// Applications should use supportedInterfaceOrientations and/or shouldAutorotate..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0) __TVOS_PROHIBITED;

应用程序建议你使用supportedInterfaceOrientations和shouldAutorotate两个方法设置支持的转屏方向,stackOverflow上很多人说这个方法doesn’t work,是用错了方法了而已。

5、让设备跟着自己肖像旋转

- (BOOL)shouldAutorotate {
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

怎么转你都是正面。

6、Upside Down选中后shouldAutorotate这几个方法不执行了在iPad上。

why?

7、…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morris_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值