iOS11和iPhone X 的簡單適配
1、iPhone X 發(fā)布以后發(fā)現(xiàn)APP的啟動頁沒有鋪滿
解決方法:在LaunchImage添加一張iPhone X的啟動頁圖片1125 × 2436或者是直接用LaunchScreen,xib或者LaunchScreen.storyboard進行配置啟動圖。
2、iPhone X的NavigatinBar和tabbar的高度變化
NavigationBar的高度變?yōu)?8,原因是狀態(tài)欄變成了40,tabbar的高度也變成了83,多增加了34, 34為底部的安全區(qū)域間距。對于我們已前寫頁面時SCREEN_HEIGHT-64-49在iPhone上會出現(xiàn)問題,導致tableview無法全部顯示,解決辦法是判斷iPhone X的時候相應的減去88和83,最好是用宏來寫,不用每個頁面都去改。
#define NavigationBarHeight (SCREEN_HEIGTH ==?812.0??88?:64)
#define TabbarHeight (SCREEN_HEIGTH ==?812.0??83?:49)
在沒有tabbar的時候,如果僅僅是SCREEN_HEIGHT-NavigationBarHeight那么底部區(qū)域會被
iPhone X這個黑條遮住,如果不喜歡遮住可以減去34。
3、iOS 11下tableview會向下偏移64或20高度
這是因為iOS11中廢棄了automaticallyAdjustsScrollViewInsets,用contentInsetAdjustmentBehavior來代替。
解決辦法:?if?(@available(iOS11.0, *)){
? ? ????????????????? ? [UIScrollView appearance].contentInsetAdjustmentBehavior = ? ? ?UIScrollViewContentInsetAdjustmentNever;
? ? }
但是這種情況下,如果調用系統(tǒng)相冊會發(fā)現(xiàn)系統(tǒng)界面上移,我也是看到別人的解決方案,在進入相冊的時候:
?if (@available(iOS 11.0, *)) {
[UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
? ? }
退出相冊是再次調用:
if (@available(iOS 11.0, *)) {
[UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
? ? }
4、iOS 11后發(fā)現(xiàn)之前寫的tableview設置的分區(qū)頭視圖高度沒有了
原代碼:
此方法在iOS11后不起作用了,如果在iOS11中不實現(xiàn)-tableView: viewForHeaderInSection: 和-tableView: viewForFooterInSection: ,則-tableView: heightForHeaderInSection: 和?-tableView: heightForFooterInSection:不會被調用,tableView在iOS11默認使用了self-sizing。
解決方法: if (@available(iOS 11.0, *)) {
? ? ? ? self.tableView.estimatedSectionHeaderHeight =15;
? ? }
5、刷新tableview的時候出現(xiàn)閃動
我是在單獨刷新某一行的時候發(fā)現(xiàn)會閃動一下
解決方法: _tableView.estimatedRowHeight = 0;
? ? ? ? ????????????_tableView.estimatedSectionHeaderHeight = 0;
? ? ? ????????????? _tableView.estimatedSectionFooterHeight = 0;
6、iOS11后導航欄設置透明失效
解決方案: