前言
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)致整個項目運行就會不能完全貼合。
解決辦法,在項目設(shè)置里面直接用LaunchScreen.xib或者LaunchScreen.storyboard進(jìn)行配置啟動圖,這樣項目就會完整顯示了
- TableView -->MJRefresh
出現(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 の変更點