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

探讨iPhoneX在iOS11后的交互变化,包括取消Home键的影响,详解contentInsetAdjustmentBehavior属性设置,以及如何调整tableView以适应新的安全区域。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景:

关键属性:

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);

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值