iPhoneX适配

https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/

http://www.jianshu.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 切换过来,顶部出现状态栏白边。

 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 有些点击导航栏 不会置顶

网页内部也做了 滚动条导致。真要处理 让h5端看一下。
  1. uitableview 可能需要关掉属性
    self.tableView.estimatedRowHeight=0;
    self.tableView.estimatedSectionHeaderHeight=0;
    self.tableView.estimatedSectionHeaderHeight=0;

6.实现大标题的代码

    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;
  1. UINavigationBar 适配

UIToolbar 和 UINavigaBar 做了新的自动布局扩展支持,自定义的bar button items、自定义的title都可以通过layout来表示尺寸

8.1Avoiding Zero-Sized Custom Views

自定义视图的size为0是因为你有一些模糊的约束布局。要避免视图尺寸为0,可以从以下方面做:

UINavigationBar 和 UIToolbar 提供位置

开发者则必须提供视图的size,有三种方式:

对宽度和高度的约束;

实现 intrinsicContentSize;

通过约束关联你的子视图;

8.2管理margins 和 insets

layout margins

基于约束的Auto Layout,使我们搭建能够动态响应内部和外部变化的用户界面。Auto Layout为每一个view都定义了margin。margin指的是控件显示内容部分的边缘和控件边缘的距离。
可以用layoutMargins或者layoutMarginsGuide属性获得view的margin,margin是视图内部的一部分。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属性读出该值。如下图所示:
iPhoneX适配_第1张图片

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是描述你的视图部分不被任何内容遮挡的方法。 它提供两种方式:safeAreaInsets或safeAreaLayoutGuide来提供给你safeArea的参照值,即 insets 或者 layout guide。

iPhoneX适配_第2张图片
image.png

9.1
如果你的APP中使用的是自定义的navigationbar,隐藏掉系统的navigationbar,并且tableView的frame为(0,0,SCREEN_WIDTH, SCREEN_HEIGHT)开始,那么系统会自动调整SafeAreaInsets值为(20,0,0,0),如果使用了系统的navigationbar,那么SafeAreaInsets值为(64,0,0,0),如果也使用了系统的tabbar,那么SafeAreaInsets值为(64,0,49,0)。关于什么情况下会发生内容下移的问题,本文第三部分有介绍。

系统自动调整tableView内容偏移量,是根据安全区域来调整的。

iPhoneX适配_第3张图片
image.png

安全区域帮助我们将view放置在整个屏幕的可视的部分。即使把navigationbar设置为透明的,系统也认为安全区域是从navigationbar的bottom开始的。
安全区域定义了view中可视区域的部分,保证不被系统的状态栏、或父视图提供的view如导航栏覆盖。可以使用additionalSafeAreaInsets去扩展安全区域去包括自定义的content在你的界面。每个view都可以改变安全区域嵌入的大小,Controller也可以。

safeAreaInsets属性反映了一个view距离该view的安全区域的边距。对于一个Controller的根视图而言,SafeAreaInsets值包括了被statusbar和其他可视的bars覆盖的区域和其他通过additionalSafeAreaInsets自定义的insets值。对于view层次中得其他view,SafeAreaInsets值反映了view被覆盖的部分。如果一个view全部在它父视图的安全区域内,则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,内容和上面字段保持一致即可。

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);
是一样的。推荐用下面那种。 上面那种会飘。系统有一个矫正的过程。

设置约束 不起作用。
[searchBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(40);
make.height.mas_equalTo(31);
}];

11.新的图标
xcode9新打包要在构建版本的时候加入1024*1024 AppSore icon

你可能感兴趣的:(iPhoneX适配)