IOS iPhoneX适配以及常用适配属性和自定义导航栏配置

版权声明:最短的时间最核心的知识,有疑问,欢迎进行留言。 https://blog.csdn.net/lizhidefengzi/article/details/86634587

背景:

关键属性:

ios 11之后原来automaticallyAdjustsScrollViewInsets属性无效,修改为

    @available(iOS 11.0, *)
    public enum ContentInsetAdjustmentBehavior : Int {

        
        case automatic // 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

        case scrollableAxes // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)

        case never // contentInset is not adjusted

        case always // contentInset is always adjusted by the scroll view's safeAreaInsets
    }

contentInsetAdjustmentBehavior

设置内容边距(contentInset)(举例:tableView距离屏幕上下左右的距离)自动调整设置常用设置属性有两种:

  • automatic   自动调整滚动区域为安全区域,自动实现适配
  • nerver   用户自己管理

automatic 设置后,自定义导航栏会出现顶部有白色区域出现

nerver 设置后用户自己管理,对应需要的属性设计有:

tableView设置为例

            self.tableView.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 34, right: 0)

相关属性:

用于设置调整行高,都是预估高度,再iOS11之前默认是0,iOS11设置为0,表示关闭预估高度,对应使用应配套使用。

self.tableView.estimatedRowHeight = 0
self.tableView.estimatedSectionFooterHeight = 0
self.tableView.estimatedSectionHeaderHeight = 0

其他

  • edgesForExtendedLayout   属性字面意思:扩展布局的边缘设置,指定边缘的延伸方向,默认是UIRectEdgeAll,
  •  self.automaticallyAdjustsScrollViewInsets = false  --是否自动判断滚动视图的内边距
  • self.extendedLayoutIncludesOpaqueBars = true  延伸视图包不包含不透明的Bar
  • modalPresentationCapturesStatusBarAppearance 当前控制器present一个其他控制器上的非全屏界面我们是否接管status bar的外观,默认是NO,(我们从一个界面A present另一个全屏界面B时,status Bar 的外观控制被转交给被B )

有时候需要设置tableView的滚动条偏移:

self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 49, 0);

猜你喜欢

转载自blog.csdn.net/lizhidefengzi/article/details/86634587