Git Product home page Git Product logo

eachnavigationbar's Introduction

EachNavigationBar

Lint Version Carthage compatible License Platform 中文文档

中文文档

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9.0
  • Swift 4.2

Installation

EachNavigationBar is available through CocoaPods or Carthage. To install it, simply add the following line to your Podfile or Cartfile:

Podfile

pod 'EachNavigationBar'

Cartfile

github "Pircate/EachNavigationBar"

Overview

Usage

Import

import EachNavigationBar

Enable

let nav = UINavigationController(rootViewController: vc)
nav.navigation.configuration.isEnabled = true

Setting

Global

nav.navigation.configuration.titleTextAttributes = [.foregroundColor: UIColor.blue]

nav.navigation.configuration.barTintColor = UIColor.red

nav.navigation.configuration.shadowImage = UIImage(named: "shadow")

nav.navigation.configuration.setBackgroundImage(UIImage(named: "nav"), for: .any, barMetrics: .default)

nav.navigation.configuration.backItem = UINavigationController.Configuration.BackItem(style: .title("返回"))

nav.navigation.configuration.prefersLargeTitles = true

nav.navigation.configuration.largeTitle.displayMode = .always

Each view controller

Normal
navigation.bar  -> EachNavigationBar -> UINavigationBar
navigation.item -> UINavigationItem

// hide navigation bar
navigation.bar.isHidden = true

// remove blur effect
navigation.bar.isTranslucent = false

// hides shadow image
navigation.bar.isShadowHidden = true

// set status bar style
navigation.bar.statusBarStyle = .lightContent

// if you want change navigation bar position
navigation.bar.automaticallyAdjustsPosition = false

// item padding
navigation.bar.layoutPaddings = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8)

// shadow
navigation.bar.shadow = Shadow(
    color: UIColor.black.cgColor,
    opacity: 0.5,
    offset: CGSize(width: 0, height: 3)
)

Alpha

// set bar alpha
navigation.bar.alpha = 0.5

// set title alpha
navigation.bar.setTitleAlpha(0.5)

// set barButtonItem alpha
navigation.bar.setTintAlpha(0.5)
// if barButtonItem is customView
navigation.item.leftBarButtonItem?.customView?.alpha = 0.5
// if barButtonItem customized tintColor
navigation.item.leftBarButtonItem?.tintColor = navigation.item.leftBarButtonItem?.tintColor?.withAlphaComponent(0.5)

Additional height or view

// navigation bar additional height
navigation.bar.additionalHeight = 14

// navigation bar additional view
navigation.bar.additionalView = UIView()

BackBarButtonItem

// set back bar button item
navigation.bar.backBarButtonItem = .init(style: .title("Back"), tintColor: .red)

// allow back
navigation.bar.backBarButtonItem.shouldBack = { item in
    // do something
    return false
}

// handler before back
navigation.bar.backBarButtonItem.willBack = {
    // do something
}

// handler after back
navigation.bar.backBarButtonItem.didBack = {
    // do something
}

LargeTitle(iOS 11.0+)

// enable
navigation.bar.prefersLargeTitles = true

// display mode
navigation.item.largeTitleDisplayMode = .always

// alpha
navigation.bar.setLargeTitleAlpha(0.5)

Author

Pircate, [email protected]

License

EachNavigationBar is available under the MIT license. See the LICENSE file for more info.

eachnavigationbar's People

Contributors

dependabot[bot] avatar lixiang1994 avatar pircate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eachnavigationbar's Issues

设计缺陷?

假设:

let vcs = self.navigationController?.viewControllers ?? []
self.navigationController?.setViewControllers(vcs.reversed(), animated: true)

setupNavigationBarWhenViewDidLoad()中的backBarButtonItem处理是不是就会有问题?

标题获取错误问题

当前FirstVC会触发2种情况:

A. 正常的push下一个VC

B. 通过present展示modal:

       let eVC = FormViewController()
        eVC.title = "Form"
        let modal = MainNavigationController(rootViewController: eVC)
        self.present(modal, animated: true, completion: nil)

具体调用思路:

Root -> MainNavigationController -> FirstVC

A. FirstVC -> (Push) -> NextVc (标题为:Next)

B. FirstVC -> (Present Modal)-> MainNavigationController -> FormVC (标题为:Form)

出现的标题情况:

A. 显示为Next (正常)

B. 显示为Next(异常,标题应该显示为Form)

demo中的NextViewController的scrollViewDidScroll方法随着界面上下迅速滚动然后侧滑返回(多试几次),navigation.bar.alpha导致崩溃

The wrong location:
extension NextViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let alpha = 1 - (scrollView.contentOffset.y) / (scrollView.contentSize.height - view.bounds.height)
navigation.bar.alpha = alpha
}
}

Error tip: Assertion failed: Please make sure UINavigationController navigation.configuration.isEnabled is true.: file EachNavigationBar/UIViewController+Navigation.swift.

A temporary change:
if ((navigationController?.navigation.configuration.isEnabled) != nil) {
navigation.bar.alpha = alpha
}
This's OK.

导航右侧按钮样式无法全局配置

class EachNavigationBar line 71. 无法配置导航按钮样式 buttonAppearance无法赋值.

private lazy var appearance: UINavigationBarAppearance = {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = self.barTintColor
appearance.titleTextAttributes = self.titleTextAttributes ?? [:]
appearance.largeTitleTextAttributes = self.largeTitleTextAttributes ?? [:]

    return appearance
}()

Bar Back Item custom(Button) - issue

I encounter a weird issue when I am using backItem
The navigation.configuration.backItem = .init(style: .custom(backButton))
after you push 2x to another controller it will show this issue when the user taps on the backItem button (custom)
the navigation pop 2x. this happens when I used .init(style: .custom(backButton)) but when i used the title and image it works fine. also tried to use the completion barkitem willBack , goBack and didBack for the custom to control those weird behavior that I encounter. I believe the button action target calls the number of stacks when the navigation push.

Cannot Add New SearchController to NavigationBar

I tried to add searchController with this code but even in debug view hierarchy it doesn't appear.

navigation.item.searchController = UISearchController(searchResultsController: nil)
navigation.item.searchController?.searchBar.isHidden = false
navigation.item.searchController?.hidesNavigationBarDuringPresentation = false

无法使用Storyboard的方法

首先,感谢如此之快的支持。谢谢!

在当前版本1.6.1:

  1. 无法触发navigationItem跳转Segue,push下一个controller
  2. 无法触发IBAction的方法

image

动画问题

前后两个navigationBar颜色一样时动画最好跟系统一样

star!!!

能否获取到滑动返回的事件?

edgesForExtendedLayout

貌似不支持self.edgesForExtendedLayout = []

// NextViewController.swift
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white
        view.addSubview(scrollView)
        view.addSubview(tipLabel)
        
        navigation.item.title = "Next"
        navigation.bar.tintColor = nil
        
        let titleView = UITextField(frame: CGRect(x: 0, y: 0, width: view.bounds.width - 100, height: 30))
        titleView.backgroundColor = UIColor.lightGray
        titleView.layer.cornerRadius = 15
        titleView.layer.masksToBounds = true
        navigation.item.titleView = titleView
        self.edgesForExtendedLayout = []
        if #available(iOS 11.0, *) {
            navigation.bar.prefersLargeTitles = false
        }
        
        navigation.bar.backBarButtonItem?.shouldBack = { item in
            let alert = UIAlertController(title: "确定退出", message: nil, preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil))
            alert.addAction(UIAlertAction(title: "确定", style: .default) { _ in
                item.goBack()
            })
            self.present(alert, animated: true, completion: nil)
            debugPrint("shouldBack")
            return false
        }
    }

Simulator Screen Shot - iPhone 11 Pro Max - 2020-09-08 at 10 44 03

设置statusBarStyle无效

navigation.bar.statusBarStyle = .lightContent
这样设置没效果
请问哪里还需要设置呢?

返回按钮的位置问题

这是原生的样子:
image

这是我尝试想要的:
image

图片2:
image

可否提供offset设置?并且,内置一个漂亮的图标+文字的返回?

断言的必要性

下面的断言条件base.navigationController?.navigation.configuration.isEnabled == true 是否是必要的?
通常在controller 侧滑手势进行中的时候, controllernavigationController是为nil的.
在这个时候修改任何属性都会触发断言, 例如网络请求 修改navigation.item.title.
或者在controllerinit方法中设置navigation.item的属性也很难受.

    var bar: EachNavigationBar {
        assert(
            !(base is UINavigationController),
            "UINavigationController can't use this property, please use configuration."
        )
        assert(
            base.navigationController?.navigation.configuration.isEnabled == true,
            "Please make sure UINavigationController navigation.configuration.isEnabled is true."
        )
        return base._navigationBar
    }
    
    var item: UINavigationItem {
        assert(
            !(base is UINavigationController),
            "UINavigationController can't use this property, please use configuration."
        )
        assert(
            base.navigationController?.navigation.configuration.isEnabled == true,
            "Please make sure UINavigationController navigation.configuration.isEnabled is true."
        )
        return base._navigationItem
    }

建议支持开启后再关闭

建议支持开启配置后,又可以关闭配置。
场景:使用到第三方的控制器,不方便修改源码的时候

方案1:AOP, 看下是是否方便实现原生的方案,而不用创建一个新的Bar
方案2:navigation.configuration.isEnabled = false 还原现场,还原原生的样式

Help needed: BackItem broken for UITests

Since bringing this (fantastic) library in, my UI test has failed when trying to press the back button in the navigation bar. Do you know if there is a trick to getting it tappable at all?
I used to have app.navigationBars.buttons.element(boundBy: 0).tap(), but that is now failing with

Failed to synthesize event: Failed to scroll to visible (by AX action) Button, label: 'Back', error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 15737, elementOrHash.elementID: 105553178871296.256. (Underlying Error: Error kAXErrorCannotComplete performing AXAction 2003 on element AX element pid: 15737, elementOrHash.elementID: 105553178871296.256)

Any help appreciated.
Thanks a lot
Luke

升级1.15.1版本后,导航栏高度显示异常

旧版本 1.15.0没问题;
升级后出现导航栏高度不对;
let vc = SomeVc()
let nav = BaseNavigationController(rootViewController: vc!)
nav.navigation.configuration.isEnabled = true
.present(nav, animated: true, completion: nil)

在SomeVc里再push下一个页面,导致导航栏高度不对;

不能使用edgesForExtendedLayout = UIRectEdge()

不能使用 edgesForExtendedLayout = UIRectEdge(),否则系统自带的navBar会显示在顶部,出现两个navBar

nav.setNavigationBarHidden(true, animated: false)
修改无效,UINavigationController.viewWillLayoutSubviews方法内已固定

Demo 中点击next 会崩溃

func scrollViewDidScroll(_ scrollView: UIScrollView) {
let statusBarMaxY = navigationController!.navigationBar.frame.minY

Fatal error: Unexpectedly found nil while unwrapping an Optional value

navigation.titleView 设置宽度无效

设备系统:iOS12.4.4(iOS13以上展示正常)
相关代码:
self.navigation.item.titleView = searchView
searchView.frame = CGRect(x: 0, y: kNavBarHeight, width: kScreenWidth * 0.84, height: kSearchVHeight)
在searchView重写了:
override var intrinsicContentSize: CGSize {
return UIView.layoutFittingExpandedSize
}
宽度无法正常展示

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.