iOS 11 適配以及Xcode 9小Tips

來源:互聯網
上載者:User

標籤:src   tin   integer   填充   get   好的   tar   targe   selector   

 

網上適配iOS 11的文章很多,但還是有些坑不踩不知道,這裡總結一下自己在項目中適配iOS 11的遇到的問題。

UIScrollView以及子類frame整體下移問題

之前的項目使用UIViewController的automaticallyAdjustsScrollViewInsets屬性,在iOS 11中被棄用,取而代之的是UIScrollView的 contentInsetAdjustmentBehavior。禁用在iOS11無法生效,導致整個頁面配置錯誤。

iOS11api

解決辦法可以針對iOS 11用新API:

 

if (@available(iOS 11,*)) {if ([tableview respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;}}

若還想再VC層面進行禁用可以參考如下宏

 

#define  adjustsScrollViewInsets(scrollView)do {_Pragma("clang diagnostic push")_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")if ([scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];NSInteger argument = 2;invocation.target = scrollView;invocation.selector = @selector(setContentInsetAdjustmentBehavior:);[invocation setArgument:&argument atIndex:2];[invocation retainArguments];[invocation invoke];}_Pragma("clang diagnostic pop")} while (0)

若項目中未使用automaticallyAdjustsScrollViewInsets屬性,則無需適配,繼續由系統控制就好。關於安全區域和邊距的詳細計算可參考安全區域適配總結。

UITableView的SetContentSize不準問題

iOS 11中預設開啟高度估算,在未實現viewForHeaderInSection時heightForHeaderInSection無法生效,關閉估算可以解決此bug。

 

self.tableView.estimatedRowHeight = 0;self.tableView.estimatedSectionHeaderHeight = 0;self.tableView.estimatedSectionFooterHeight = 0;

[[UIScreen mainScreen] bounds].size不對

在運行iPhone X時,發現以前定義的螢幕size宏不對。原因在於此size取得是App啟動時載入的啟動圖Size,只需在啟動圖在加入iPhone X尺寸的啟動圖即可,解析度為1125*2436。

導覽列item錯亂

項目中有的控制器需要自訂導覽列左右的barItem,當左右的barItem擠滿整個bar時,push然後pop回到本控制器時,baritem的frame直接變形。如下

item

萬惡的根源是UINavigationBar中又加入了新的圖層UIButtonBarStackView,沒有自訂UINavigation真是個錯誤,迫不得已寫了新View蓋在Bar上面,手動控制起隱藏與顯示。這隻是個臨時折中辦法,若有好的方法,記得分享給我~若只是位置位移,可參考導覽列按鈕位置問題。

新iPhone的名稱

@"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",

Xcode 9小Tips

1、匯入圖片若失敗,手動在Build Phases  --->Copy Binary With Libraies中重新添加一遍即可。

2、Xcode 9 打包時,記得在icon的添加1024*1024的表徵圖。

3、雞肋的無線調試功能(iPhone的電池...)可在Window  -->Devices and Simulators中勾選那兩個選項。前提是此裝置已run過並處於同一區域網路下。

4、在Asset中,可以建立顏色了。右鍵選擇New image set,填充RGBA值或十六進位值即可。使用中直接使用新的colorwithname,參數填入建立時的名字即可。不過記得區分系統版本。

5、command鍵複原。可在Preferences --> Navigation -->Commadn-click 中選擇Jumps to Defintion即可。

6、xcode 9 還允許多開模擬器,不過公司的電腦。。。哎,不多說。

商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。

  

iOS 11 適配以及Xcode 9小Tips

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.