iOS11最终仍是来了, 此次改版屏幕尺寸, 控件特性都有一些比较大的改变. 网上看的问题零零散散, ?收集了一下开发中出现的问题, 整理一下, 方便以后使用.html
导航栏高度一直是固定的64P, 到了iOS11这个规则被打破了, 除了iPhoneX全面屏, 刘海等适配问题, 还增长了大标题的属性,
titleView
支持autolayout
;ios
//根据prefersLargeTitles设置, 默认为NO; self.navigationController.navigationBar.prefersLargeTitles = YES;下方附一个导航栏的对比图:
通常机型导航栏尺寸图(除了iPhoneX)
iPhoneX导航栏尺寸图web
sol 1: 宏定义高度objective-c
#define NAVIGATION_HEIGHT (CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) + CGRectGetHeight(self.navigationController.navigationBar.frame)) #ifdef __IPHONE_11_0 if (@available(iOS 11.0, *)) { self.navigationBar.frame = CGRectMake(0, STATUSBAR_HEIGHT,ScreenWidth, NAVIGATION_HEIGHT); } #endif
sol 2: 工具类获取高度json
@implementation TestUtil + (CGFloat)navigationBarHeight { if (IS_iPhoneX) { return 88.0f; } return 64.0f; } @end #define IS_iPhoneX ([UIScreen mainScreen].bounds.size.width == 375 && [UIScreen mainScreen].bounds.size.height == 812)
//titleView自扩展尺寸, 须要自定义view实现该方法 - (CGSize)intrinsicContentSize { return UILayoutFittingExpandedSize; }
返回按钮向下偏移;安全
//设置navigationController的backIndicatorImage和backIndicatorTransitionMaskImage UIImage *backButtonImage = [[UIImage imageNamed:@"icon_tabbar_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; self.navigationBar.backIndicatorImage = backButtonImage; self.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;
关于安全区域, tableView废弃了
automaticallyAdjustsScrollViewInsets
属性;estimatedRowHeight
,estimatedSectionHeaderHeight
estimatedSectionFooterHeight
三个高度估算属性由默认的0变成了UITableViewAutomaticDimension
;固然了, 这个是形成UI紊乱的缘由, 值得一提的是tableView的新特性;app
- 设置
delaysContentTouches
为NO
, 不会当即触发cell的响应事件;- 两根手指快速的轻击cell,能够同时选中两个cell进入编辑状态。若是两个手指存在不一样步问题,则会默认识别其中的一个手指表示单选cell;
- 新增了一个属性
separatorInsetReference
能够自定义一个cell分割线的边距;- cell或者表头表尾默认采用自适应高度的方案(形成UI紊乱的缘由);
- 增长了numberOfLines属性来实现相似于UILabel同样的高度自适应变化;
automaticallyAdjustsScrollViewInsets
属性被废弃,顶部就多了一些偏移;
sol 1: iphone
if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; }
sol 2: 工具
//iOS11 解决SafeArea的问题,同时能解决pop时上级页面scrollView抖动的问题 if (@available(iOS 11, *)) { [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; }
sol 3: post
#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)
网友还出现了webView会向下移动部分距离的问题;
if (@available(iOS 11.0, *)) { webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions }
sol 1:
self.table.estimatedRowHeight = 0; self.table.estimatedSectionHeaderHeight = 0; self.table.estimatedSectionFooterHeight = 0;
sol 2:
//解决iOS11,仅实现heightForHeaderInSection,没有实现viewForHeaderInSection方法时,section间距大的问题 [UITableView appearance].estimatedRowHeight = 0; [UITableView appearance].estimatedSectionHeaderHeight = 0; [UITableView appearance].estimatedSectionFooterHeight = 0;
底部区域主要是iPhoneX与其余机型不同, 通常机型高度为49, iPhoneX为83;
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
在IOS11,原有的
NSLocationAlwaysUsageDeion
被降级为NSLocationWhenInUseUsageDeion
;
须要在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion
,系统框才会弹出;使用requestAlwaysAuthorization获取权限 IOS11系统弹框会把几种权限级别所有列出,供用户选择;
NSLocationUsageDescription 获取地理位置,精准推送服务 NSLocationWhenInUseUsageDescription 获取地理位置,精准推送服务 NSLocationAlwaysUsageDescription App须要您的赞成,才能始终访问位置 NSLocationAlwaysAndWhenInUseUsageDeion App须要您的赞成,才能始终访问位置
sol 1: 添加iPhoneX的Launch图1125x2436
使用LaunchScreen来当作缓冲页或者修改Assets中的LaunchImage,添加iPhoneX的Launch图1125*2436(竖屏);
sol 2: 修改Contents.json文件
{ "extent" : "full-screen", "idiom" : "iphone", "subtype" : "2436h", "filename" : "1125_2436.png”, "minimum-system-version" : "11.0", "orientation" : "portrait", "scale" : "3x" }
sol 2: 使用 LaunchScreen.storyboard 设置启动图
使用 LaunchScreen.storyboard 文件将简单视图约束定位,实现各类尺寸的自适应。
ReactiveCocoa Unknown warning group ‘-Wreceiver-is-weak’,ignored警告;
#define RACObserve(TARGET, KEYPATH) \ ({ \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wreceiver-is-weak\"") \ __weak id target_ = (TARGET); \ [target_ rac_valuesForKeyPath:@keypath(TARGET, KEYPATH) observer:self]; \ _Pragma("clang diagnostic pop") \ })
通常是打开之前的工程, 编译的时候xib报错, 例如:
warning: Internationalization is not available when compiling for targets before iOS 6.0
解决办法:
选择编译错误的xib文件,找到Builds for 改成iOS 7.0 and Later
iOS11之前:NSPhotoLibraryUsageDescription
:访问相册和存储照片到相册(读写),会出现用户受权;
iOS11以后:NSPhotoLibraryUsageDescription
:无需添加。默认开启访问相册权限(读),无需用户受权;NSPhotoLibraryAddUsageDescription
: 添加内容到相册(写),会出现用户受权;
这些问题是网友们趟过的坑,但愿网友们若是遇到过其余问题, 能积极补充, 共同进步;
一我的的国庆, 浪不起来, 写篇博客压压惊?
参考文章:
关于iPhone X、iOS 11 、Xcode9,咱们应该知道这些
iOS11就问你一句“惊不惊喜?意不意外?”5.8的苦笑。。。。。
iOS11 适配之导航栏、tableView、searchBar遇到的bug
简书App适配iOS 11
10分钟适配 iOS 11 & iPhone X
iOS11开发 新增功能大全
iPhone X + iOS 11 适配指南