iOS 11 與 iPhone X的適配那些事

前言

9月20日,正式推送Xcode 9 和iOS 11 的正式版,適配iOS 11是首要的適配的,網(wǎng)上教程很多,不在贅述。這里主要講的是 iPhone X的適配。大神級別的可以不用看,我這里講的主要是基礎(chǔ)的適配工作

摘要

啟動圖: 1125 * 2436
statusBar高度: 44
tabbar高度: 83

  • 啟動App

對于一些老項目,在啟動圖上,可能沒有采用xib或者SB進(jìn)行適配的,所以可能會出現(xiàn)如圖一,這樣導(dǎo)致整個項目運行就會不能完全貼合。

![Uploading login2_194373.png . . .]

解決辦法,在項目設(shè)置里面直接用LaunchScreen.xib或者LaunchScreen.storyboard進(jìn)行配置啟動圖,這樣項目就會完整顯示了


iPhone X LaunchImage.png

iPhone X LaunchImage2.png
login2.png

出現(xiàn)下拉刷新的尾巴,該問題很好解決,在文檔中標(biāo)注很明白

@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets API_DEPRECATED_WITH_REPLACEMENT("Use UIScrollView's contentInsetAdjustmentBehavior instead", ios(7.0,11.0),tvos(7.0,11.0)); // Defaults to YES

contentInsetAdjustmentBehavior對于我們現(xiàn)在來說是個陌生面孔。這是在iOS11中為ScrollView新定義的一個枚舉屬性。注意,上面談到的automaticallyAdjustsScrollViewInsets是控制器的屬性。

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
    UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
    UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
    UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
    UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
} API_AVAILABLE(ios(11.0),tvos(11.0));

iOS 11中的estimatedXXHeight由默認(rèn)的0變成了現(xiàn)在的默認(rèn).AutomaticDimension,導(dǎo)致高度計算出錯,最后導(dǎo)致的現(xiàn)象就是上拉加載更多的時候UI錯亂,TableView視圖的高度異常等一系列問題。

 if (@available(iOS 11.0, *)) {
        _newtableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        //以下是tableview高度計算出現(xiàn)問題
        _newtableView.estimatedRowHeight = 0;
        _newtableView.estimatedSectionHeaderHeight=0;
        _newtableView.estimatedSectionFooterHeight=0;
        
  }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
  }

iOS 11 NavigationBar 新特性

Navigation 集成 UISearchController
把你的UISearchController賦值給navigationItem,就可以實現(xiàn)將UISearchController集成到Navigation

navigationItem.searchController  //iOS 11 新增屬性
navigationItem.hidesSearchBarWhenScrolling //決定滑動的時候是否隱藏搜索框;iOS 11 新增屬性
@property (nonatomic, retain, nullable) UISearchController *searchController API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

總結(jié):

iOS11系統(tǒng)改變還是比較大的,某些地方需要注意適配,不然會出現(xiàn)很奇怪的現(xiàn)象。暫時,在iOS11遇到這么多坑,以后遇到會繼續(xù)分享的。
第一次寫文章,多謝關(guān)照

參考:

開發(fā)者所需要知道的 iOS 11 SDK 新特性
iOS 11導(dǎo)航欄高度自定義
iOS 11 UIKit の変更點

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 隨著iOS11和xcode9剛開始正式發(fā)布,小編也迫不及待的更新了xcode9,手機(jī)也順利更新到iOS,也終于見到...
    七秒記憶的魚兒閱讀 96,423評論 97 410
  • iOS11與iPhone X的適配 文章講解點:1.首先看一下iPhone X的模擬器樣式吧2.iPhone X的...
    iYeso閱讀 486評論 0 3
  • 蘋果公司于2017年9月13日凌晨發(fā)布了兩款新的手機(jī)—— iPhon 8與iPhone X,作為全新的屏幕樣式 i...
    LearningCoding閱讀 6,099評論 2 6
  • 會認(rèn)識林然真的可以說是天注定。 十一黃金周,李笑決定在家里宅到死。好不容易休息幾天她才不會想不開去旅游呢!這個時候...
    淡紫褐綠閱讀 671評論 2 2
  • 成功的路上沒有人會叫你起床,也沒有人為你買單,你需要自我管理,自我約束,自我突破,人都是被逼出來的,人的潛能無限,...
    wanghaokang閱讀 224評論 0 0