1、导航栏的高度的适配
iOS 11以前,状态栏statusBar的高度是20,底部tabbar的高度是49。
iOS 11之后,状态栏的statusBar的高度变成了44, 底部的tabbar变成了83
所以建议还是抽取成宏。
2、安全区域的问题
iOS 11之前, automaticallyadjustsscrollviewinsets经常被设置成NO,由开发者去控制处理留白和坐标问题。
iOS 11后,把这个automaticallyadjustsscrollviewinsets废弃,新增了
contentInsetAdjustmentBehavior,它是个枚举类型的值,我们只需要把其设置成never就行了.
#define adjustsScrollViewInsets_NO(scrollView,vc)\
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
if ([UIScrollView instancesRespondToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
[scrollView performSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:") withObject:@(2)];\
} else {\
vc.automaticallyAdjustsScrollViewInsets = NO;\
}\
_Pragma("clang diagnostic pop") \
} while (0)
3、tableview的组头和组尾高度变大问题
我们需要在初始化的把这三属性设置成0即可(
estimatedRowHeight、 estimatedSectionHeaderHeight estimatedSectionFooterHeight)
4、导航栏标题titleview的问题
iOS 11中会出现蜷缩成一起的现象 不过它现在支持autolayout。所以我们需要把它扩展出去, 只需要在你自定义的titleview中实现
- (CGSize)intrinsicContentSize {
return UILayoutFittingExpandedSize;
}
5、状态栏获取当前网络状态(3G、4G、Wifi、LTE...)
#pragma mark-获取当前网络状态
+(NSString *)getCurrentNetworkStatus{
NSString * networktype = nil;
// 因此可见iPhone X的状态栏是多嵌套了一层,多取一次即可,最终适配代码为:
NSArray *subviews;
// 不能用 [[self deviceVersion] isEqualToString:@"iPhone X"] 来判断,因为模拟器不会返回 iPhone X
if ([[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
subviews = [[[[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
} else {
subviews = [[[[UIApplication sharedApplication] valueForKeyPath:@"_statusBar"] valueForKeyPath:@"foregroundView"] subviews];
}
// NSArray *subviews = [[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"]subviews];
NSNumber *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
dataNetworkItemView = subview;
break;
}
}
switch ([[dataNetworkItemView valueForKey:@"dataNetworkType"]integerValue]) {
case 0:
networktype = @"";
break;
case 1:
networktype=@"2G";
break;
case 2:
networktype=@"3G";
break;
case 3:
networktype=@"4G";
break;
case 4:
networktype=@"LTE";
break;
case 5:
networktype=@"Wifi";
break;
default:
networktype = @"";
break;
}
return networktype;
}
6、启动图
Default-iOS11-812h.jpg7、设备内编码转换设备名
@"iPhone10,1" : @"iPhone 8",
@"iPhone10,4" : @"iPhone 8",
@"iPhone10,2" : @"iPhone 8 Plus",
@"iPhone10,5" : @"iPhone 8 Plus",
@"iPhone10,3" : @"iPhone X",
@"iPhone10,6" : @"iPhone X",
网友评论