前言
9月20日,正式推送Xcode 9 和iOS 11 的正式版,適配iOS 11是首要的適配的,網上教程很多,不在贅述。這裏主要講的是 iPhone X的適配。大神級別的可以不用看,我這裏講的主要是基礎的適配工作
摘要
啓動圖: 1125 * 2436
statusBar高度: 44
tabbar高度: 83
- 啓動App
對於一些老項目,在啓動圖上,可能沒有采用xib或者SB進行適配的,所以可能會出現如圖一,這樣導致整個項目運行就會不能完全貼合。
對於一些老項目,在啓動圖上,可能沒有采用xib或者SB進行適配的,所以可能會出現如圖一,這樣導致整個項目運行就會不能完全貼合。
解決辦法,在項目設置裏面直接用LaunchScreen.xib或者LaunchScreen.storyboard進行配置啓動圖,這樣項目就會完整顯示了
iPhone X LaunchImage.png
iPhone X LaunchImage2.png
login2.png
- TableView –>MJRefresh
出現下拉刷新的尾巴,該問題很好解決,在文檔中標註很明白
@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對於我們現在來說是個陌生面孔。這是在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由默認的0變成了現在的默認.AutomaticDimension,導致高度計算出錯,最後導致的現象就是上拉加載更多的時候UI錯亂,TableView視圖的高度異常等一系列問題。
if (@available(iOS 11.0, *)) {
_newtableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//以下是tableview高度計算出現問題
_newtableView.estimatedRowHeight = 0;
_newtableView.estimatedSectionHeaderHeight=0;
_newtableView.estimatedSectionFooterHeight=0;
}else{
self.automaticallyAdjustsScrollViewInsets = NO;
}
iOS 11 NavigationBar 新特性
Navigation 集成 UISearchController
把你的UISearchController賦值給navigationItem,就可以實現將UISearchController集成到Navigation。
navigationItem.searchController //iOS 11 新增屬性
navigationItem.hidesSearchBarWhenScrolling //決定滑動的時候是否隱藏搜索框;iOS 11 新增屬性@property (nonatomic, retain, nullable) UISearchController *searchController API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
總結:
iOS11系統改變還是比較大的,某些地方需要注意適配,不然會出現很奇怪的現象。暫時,在iOS11遇到這麼多坑,以後遇到會繼續分享的。