https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/
http://www.reibang.com/p/efbc8619d56b
http://www.cocoachina.com/ios/20170915/20580.html
define iPhoneX ([UIScreen mainScreen].bounds.size.width == 375 && [UIScreen mainScreen].bounds.size.height == 812)
define IPHONEX_MARGIN_TOP 44
define IPHONEX_MARGIN_BOTTOM 34
1.iOS11 uiwebview返回,抽瘋了位置不太對李命。 理論上所有uiscrollview都得添加
self.webView.scrollView.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
2.頁面隱藏導航欄橄务,帶有一個tableview。從其他tabbar 切換過來卵凑,頂部出現(xiàn)狀態(tài)欄白邊。
self.tableView.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
3.導航欄透明恼布、tabbar透明
//聲明tableView的位置 添加下面代碼
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
_tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0);
_tableView.scrollIndicatorInsets = _tableView.contentInset;
}
4.uiwebview 有些點擊導航欄 不會置頂
網(wǎng)頁內(nèi)部也做了 滾動條導致本慕。真要處理 讓h5端看一下糊治。
- uitableview 可能需要關掉屬性
self.tableView.estimatedRowHeight=0;
self.tableView.estimatedSectionHeaderHeight=0;
self.tableView.estimatedSectionHeaderHeight=0;
6.實現(xiàn)大標題的代碼
self.navigationItem.title=@"我愛羅";
self.navigationController.navigationBar.prefersLargeTitles=YES;
self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways;
7.iOS11 里面search controller
HomeDetailViewController *vc =[[HomeDetailViewController alloc] init];
UISearchController *searchVC=[[UISearchController alloc] initWithSearchResultsController:vc];
self.navigationItem.searchController = searchVC;
self.navigationItem.hidesSearchBarWhenScrolling=NO;
- UINavigationBar 適配
UIToolbar 和 UINavigaBar 做了新的自動布局擴展支持,自定義的bar button items丸氛、自定義的title都可以通過layout來表示尺寸
8.1Avoiding Zero-Sized Custom Views
自定義視圖的size為0是因為你有一些模糊的約束布局培愁。要避免視圖尺寸為0,可以從以下方面做:
UINavigationBar 和 UIToolbar 提供位置
開發(fā)者則必須提供視圖的size缓窜,有三種方式:
對寬度和高度的約束定续;
實現(xiàn) intrinsicContentSize;
通過約束關聯(lián)你的子視圖雹洗;
8.2管理margins 和 insets
layout margins
基于約束的Auto Layout香罐,使我們搭建能夠動態(tài)響應內(nèi)部和外部變化的用戶界面卧波。Auto Layout為每一個view都定義了margin时肿。margin指的是控件顯示內(nèi)容部分的邊緣和控件邊緣的距離。
可以用layoutMargins或者layoutMarginsGuide屬性獲得view的margin,margin是視圖內(nèi)部的一部分港粱。layoutMargins允許獲取或者設置UIEdgeInsets結構的margin螃成。layoutMarginsGuide則獲取到只讀的UILayoutGuide對象。
在iOS11新增了一個屬性:directional layout margins查坪,該屬性是NSDirectionalEdgeInsets結構體類型的屬性:
typedef struct NSDirectionalEdgeInsets {
CGFloat top, leading, bottom, trailing;
} NSDirectionalEdgeInsets API_AVAILABLE(ios(11.0),tvos(11.0),watchos(4.0));
layoutMargins是UIEdgeInsets結構體類型的屬性:
typedef struct UIEdgeInsets {
CGFloat top, left, bottom, right;
} UIEdgeInsets;
從上面兩種結構體的對比可以看出寸宏,NSDirectionalEdgeInsets 屬性用leading 和 trailing 取代了之前的 left 和 right。
directional layout margins屬性的說明如下:
directionalLayoutMargins.leading is used on the left when the user interface direction is LTR and on the right for RTL.
Vice versa for directionalLayoutMargins.trailing.
例子:當你設置了trailing = 30偿曙;當在一個right to left 語言下trailing的值會被設置在view的左邊氮凝,可以通過layoutMargin的left屬性讀出該值。如下圖所示:
9.Safe Area基礎
self.edgesForExtendedLayout = UIRectEdgeNone是會對整個頁面的控件的坐標起到作用的望忆,而self.automaticallyAdjustsScrollViewInsets = NO 是只針對于UIScrollView的罩阵。
//iOS6布局 從64開始算
edgesForExtendedLayout = UIRectEdgeNone
//iOS7 從0開始算
edgesForExtendedLayout = UIRectEdgeAll
iOS 7 UIViewController中引入的 topLayoutGuide 和 bottomLayoutGuide 【iOS11廢棄】
iOS11 采用SafeArea是描述你的視圖部分不被任何內(nèi)容遮擋的方法。 它提供兩種方式:safeAreaInsets或safeAreaLayoutGuide來提供給你safeArea的參照值启摄,即 insets 或者 layout guide稿壁。
9.1
如果你的APP中使用的是自定義的navigationbar,隱藏掉系統(tǒng)的navigationbar歉备,并且tableView的frame為(0,0,SCREEN_WIDTH, SCREEN_HEIGHT)開始傅是,那么系統(tǒng)會自動調(diào)整SafeAreaInsets值為(20,0,0,0),如果使用了系統(tǒng)的navigationbar蕾羊,那么SafeAreaInsets值為(64,0,0,0)喧笔,如果也使用了系統(tǒng)的tabbar,那么SafeAreaInsets值為(64,0,49,0)龟再。關于什么情況下會發(fā)生內(nèi)容下移的問題实辑,本文第三部分有介紹炊甲。
系統(tǒng)自動調(diào)整tableView內(nèi)容偏移量,是根據(jù)安全區(qū)域來調(diào)整的渡嚣。
安全區(qū)域幫助我們將view放置在整個屏幕的可視的部分。即使把navigationbar設置為透明的嗽冒,系統(tǒng)也認為安全區(qū)域是從navigationbar的bottom開始的。
安全區(qū)域定義了view中可視區(qū)域的部分,保證不被系統(tǒng)的狀態(tài)欄蛉威、或父視圖提供的view如導航欄覆蓋∽卟福可以使用additionalSafeAreaInsets去擴展安全區(qū)域去包括自定義的content在你的界面蚯嫌。每個view都可以改變安全區(qū)域嵌入的大小,Controller也可以丙躏。
safeAreaInsets屬性反映了一個view距離該view的安全區(qū)域的邊距择示。對于一個Controller的根視圖而言,SafeAreaInsets值包括了被statusbar和其他可視的bars覆蓋的區(qū)域和其他通過additionalSafeAreaInsets自定義的insets值晒旅。對于view層次中得其他view栅盲,SafeAreaInsets值反映了view被覆蓋的部分。如果一個view全部在它父視圖的安全區(qū)域內(nèi)废恋,則SafeAreaInsets值為(0,0,0,0)谈秫。
10.titleview
- (CGSize)intrinsicContentSize
{
return UILayoutFittingExpandedSize;
}
11.相冊權限需要增加,不然會造成閃退喲
增加info.Plist中的字段:
之前的這個字段:Privacy - Photo Library Usage Description
需要增加這個字段Privacy - Photo Library Additions Usage Description鱼鼓,內(nèi)容和上面字段保持一致即可拟烫。
12.簡潔6句話適配
if (@available(ios 11.0,*)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
UITableView.appearance.estimatedRowHeight = 0;
UITableView.appearance.estimatedSectionFooterHeight = 0;
UITableView.appearance.estimatedSectionHeaderHeight = 0;
}
//適配uiwebview
+(void)adapterWebview:(UIWebView *)webView
{
if(kiOS11)
{
webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
11.iOS 10
導航 titleview = searchBarView。
searchBarView.frame = CGRectMake(0, 0, SCREEN_WIDTH-80, 31);
searchBarView.frame = CGRectMake(40, 0, SCREEN_WIDTH-80, 31);
是一樣的迄本。推薦用下面那種硕淑。 上面那種會飄。系統(tǒng)有一個矯正的過程嘉赎。
設置約束 不起作用置媳。
[searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(40);
make.height.mas_equalTo(31);
}];
11.新的圖標
xcode9新打包要在構建版本的時候加入1024*1024 AppSore icon