Giter Site home page Giter Site logo

navhiddendemo's Introduction

NavHiddenDemo

导航栏的展示和隐藏跳转

  1. 背景

    开发中经常遇到类似于网易云音乐个人中心的,导航栏透明滑动到不透明,跳转等操作

    效果展示

  2. 情况1 没有导航栏,变成有导航栏系统提供了方法

    navigationController.setNavigationBarHidden(true, animated: true)
  1. 情况2 有导航栏,和一些按钮和标题,只不过是隐藏的

首先需要设置以下属性

    //隐藏导航栏的背景和线
    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationController?.navigationBar.shadowImage = UIImage()
    
    //不自动调整contentInset
    if #available(iOS 11.0, *) {
        tableView.contentInsetAdjustmentBehavior = .never
    } else {
        automaticallyAdjustsScrollViewInsets = false
    }
    //从顶部开始布局
    extendedLayoutIncludesOpaqueBars = true

提供导航栏隐藏的扩展UINavigationController+Hidden.swift

    func hideNavigationBarBGView() {
        navigationBar.isTranslucent = true
        navigationBar.barTintColor = .clear
    }
    
    func showNavigationBarBGView() {
        navigationBar.isTranslucent = false
        navigationBar.barTintColor = .white
    }

根据scrollview的contentOffset进行隐藏和展示

    private func updateNavigationBarStyle() {
        let anchor: CGFloat = Constant.navBarShowContentOffectY
        if tableView.contentOffset.y < anchor {
            hideNavigationBarBGView()
        } else {
            showNavigationBarBGView()
        }
    }

demo中包含了对ios10以下设备的一些兼容处理

navhiddendemo's People

Contributors

tsnumidc avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.