记录一下项目里面两个 iPhoneX 适配的问题。
1、整个APP 顶部和底部有黑色空白的区域。
原因:启动页面没有适配iPhoneX
如图:
WX20180309-164025.png WX20180309-163956.png
解决办法:添加iphone X启动图
//contents.json 图片尺寸 1125 x 2436
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "2436h",
"filename" : "Default-2436h.png",
"minimum-system-version" : "11.0",
"orientation" : "portrait",
"scale" : "3x"
}
正常情况下的样子:
WX20180309-164708.png WX20180309-164715.png
2、图片尺寸太小导致图片分层重叠
如图:
WX20180309-165109.png
分割线以上是完整的图片,下面是多余的。这种情况只需要一个合适大小的图片就行
ps:导航栏设置图片也会出现这样的情况。
3、通过系统statusBar判断网路状态时,导致Crash
解决方法:
+ (NSString *)currentNetworkType
{
NSArray *children;
UIApplication *app = [UIApplication sharedApplication];
NSString *state = [[NSString alloc] init];
//iPhone X
if ([[app valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
children = [[[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
for (UIView *view in children) {
for (id child in view.subviews) {
//wifi
if ([child isKindOfClass:NSClassFromString(@"_UIStatusBarWifiSignalView")]) {
state = @"wifi";
}
//2G 3G 4G
if ([child isKindOfClass:NSClassFromString(@"_UIStatusBarStringView")]) {
if ([[child valueForKey:@"_originalText"] containsString:@"G"]) {
state = [child valueForKey:@"_originalText"];
}
}
}
}
if (state.length <= 0) {
state = @"无网络";
}
}else {
children = [[[app valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
for (id child in children) {
if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
//获取到状态栏
switch ([[child valueForKeyPath:@"dataNetworkType"] intValue]) {
case 0:
state = @"无网络";
//无网模式
break;
case 1:
state = @"2G";
break;
case 2:
state = @"3G";
break;
case 3:
state = @"4G";
break;
case 5:
state = @"wifi";
break;
default:
break;
}
}
}
}
return state;
}
如有不对的地方,欢迎指出!
网友评论