提前尝试了下用Xcode GM版本感受了下iphoneX 和 iOS11。发现了项目里的一些问题。(ps.这些问题网上大多帖子都有讲到,这里只是做个简单的小总结)
iOS 11是适配
1.iOS11中ViewController的automaticallyAdjustsScrollViewInsets属性被废弃了,部分界面出现了问题。处理:
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
1.1目前发现所有的Scrollview 及其子类都需要设置 contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever ,工程中大量使用列表的同学不要慌,不要忙,因为UIView及其子类都遵循UIAppearance协议,我们可以进行全局配置
// AppDelegate 进行全局设置
if (@available(iOS 11.0, *)){
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
iphoneX的是适配
1.刘海的设置。导航栏高度为88,之前导航栏的高度是写死的 64 ,纯代码布局会有一些这样的问题。
添加判断:
#define IPHONE_X_HEIGHT 812
/** 导航栏高度 */
#define NAVBAR_HEIGHT ((NSInteger)SCREEN_HEIGHT == IPHONE_X_HEIGHT ? 88 : 64)
/** 送几个宏 */
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
2.iphoneX根据状态栏获取当前网络状态会奔溃(目前是注释掉了,用AFN的监控代替了)
UIApplication *app = [UIApplication sharedApplication];
NSArray *children = [[[app valueForKeyPath:@"statusBar"]valueForKeyPath:@"foregroundView"]subviews];
NSString *state = [[NSString alloc]init];
int netType = 0;
//获取到网络返回码
for (id child in children) {
if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
//获取到状态栏
netType = [[child valueForKeyPath:@"dataNetworkType"]intValue];
switch (netType) {
case 0:
state = @"无网络";
//无网模式
break;
case 1:
state = @"2G";
break;
case 2:
state = @"3G";
break;
case 3:
state = @"4G";
break;
case 5:
{
state = @"wifi";
[self fetchSSIDInfo];
}
break;
default:
break;
}
}
}
//根据状态选择
self.network = [NSString stringWithFormat:@"network=%@",state];