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 適配指南