pircate / eachnavigationbar Goto Github PK
View Code? Open in Web Editor NEWA custom navigation bar for each view controller.
License: MIT License
A custom navigation bar for each view controller.
License: MIT License
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.
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
下面的断言条件base.navigationController?.navigation.configuration.isEnabled == true
是否是必要的?
通常在controller 侧滑手势进行中的时候, controller
的navigationController
是为nil
的.
在这个时候修改任何属性都会触发断言, 例如网络请求 修改navigation.item.title
.
或者在controller
的init
方法中设置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
}
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
之前用nav.navigation.configuration.backBarButtonItem 全局配置nav的返回按钮为一个图片。
现在取消了这个特性,要在每一个vc中添加。。。能再加上么。。
iOS 13 demo无法进行侧滑返回上一页
navigation.bar.statusBarStyle = .lightContent
这样设置没效果
请问哪里还需要设置呢?
如题
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)
假设:
let vcs = self.navigationController?.viewControllers ?? []
self.navigationController?.setViewControllers(vcs.reversed(), animated: true)
setupNavigationBarWhenViewDidLoad()
中的backBarButtonItem
处理是不是就会有问题?
场景 应用内黑白主题切换 主题发生变化是 重新设置navigation.configuration.barTintColor 并未立刻更新, 或者是否有提供手动触发UI刷新的方法?
建议支持开启配置后,又可以关闭配置。
场景:使用到第三方的控制器,不方便修改源码的时候
方案1:AOP, 看下是是否方便实现原生的方案,而不用创建一个新的Bar
方案2:navigation.configuration.isEnabled = false 还原现场,还原原生的样式
self.view一直是全屏大小,设置约束时必须使用self.view.safeAreaInsets.top
希望能内部修改self.view.top = self._navigationBar.bottom
旧版本 1.15.0没问题;
升级后出现导航栏高度不对;
let vc = SomeVc()
let nav = BaseNavigationController(rootViewController: vc!)
nav.navigation.configuration.isEnabled = true
.present(nav, animated: true, completion: nil)
在SomeVc里再push下一个页面,导致导航栏高度不对;
前后两个navigationBar颜色一样时动画最好跟系统一样
貌似不支持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
}
}
不能使用 edgesForExtendedLayout = UIRectEdge()
,否则系统自带的navBar会显示在顶部,出现两个navBar
nav.setNavigationBarHidden(true, animated: false)
修改无效,UINavigationController.viewWillLayoutSubviews
方法内已固定
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
}()
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let statusBarMaxY = navigationController!.navigationBar.frame.minY
Fatal error: Unexpectedly found nil while unwrapping an Optional value
你好,请问页面push后导航栏整体下移是为什么
横竖屏下状态栏高度也不一样?
The example project could not find UINavigationBarAppearance
一运行就报错了 找不到EachNavigationBar/EachNavigationBar-Swift.h OC 语言
有点不懂,是有什么 bug 导致必须这样做吗
如题,什么都没改,手势就没用
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.
能否获取到滑动返回的事件?
设备系统: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
}
宽度无法正常展示
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.