浅谈iOS导航栏布局问题

2018-07-19  本文已影响0人  alex_zn

iOS 安全区域

主要设计几个属性 automaticallyAdjustsScrollViewInsets,contentInsetAdjustmentBehavior,adjustedContentInset,edgesForExtendedLayout

iOS11 安全区域后由topLayoutGuider 改为 safeGuider作为相对依赖
导航栏透明属性后,scrollview属性的view push是 会由控制器 automaticallyAdjustsScrollViewInsets(iOS10),adjustedContentInset(iOS11) 自动加上 nav的高度,

// 普通控制器
    private func initLayoutUI() {

        // 禁用系统滚动视图布局 ios10
        automaticallyAdjustsScrollViewInsets = false
        // 布局
        contentView.snp.makeConstraints { (make) in

            if #available(iOS 11.0, *) {

                if navBgBarTransEnable == true {

                    make.top.bottom.equalTo(0)
                    edgesForExtendedLayout = .top
                } else {

                    make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
                    make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
                }

            } else {

                if navBgBarTransEnable == true {

                    edgesForExtendedLayout = .top
                    make.top.bottom.equalToSuperview()
                } else {

                    make.top.equalTo(topLayoutGuide.snp.bottom)
                    make.bottom.equalTo(bottomLayoutGuide.snp.top)
                }
            }

            make.left.right.equalToSuperview()
        }
    }
    
// tablevivew
        if #available(iOS 11, *) {

            if navBgBarTransEnable == true {

                tableView.contentInsetAdjustmentBehavior = .never
            } else {
                
                tableView.contentInsetAdjustmentBehavior = .automatic
            }

            //tableView.contentInsetAdjustmentBehavior = .automatic

        } else {

            if navBgBarTransEnable == true {

                automaticallyAdjustsScrollViewInsets = false
            } else {

                automaticallyAdjustsScrollViewInsets = true
            }

        }

上一篇下一篇

猜你喜欢

热点阅读