Navigation bar 的注意事项
Navigation bar 的注意事项
Bar button item 使用 button 作为 custom view,初始化 isEnabled 为 false,注意顺序
需要设置 bar button item 的 custom view 为 button,但一开始 isEnabled 要为 false。
生成一个 button
let leftButton = UIButton(frame: CGRect(x: 0, y: 0, width: 80, height: 44))
leftButton.setTitleColor(UIColor.green, for: .normal)
leftButton.setTitleColor(UIColor.red, for: .disabled)
leftButton.setTitle("Enabled", for: .normal)
leftButton.setTitle("Disabled", for: .disabled)
leftButton.addTarget(self, action: #selector(leftButtonClicked(_:)), for: .touchUpInside)
如果先设置 isEnabled,后设置 bar button item
leftButton.isEnabled = false
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftButton)
结果 isEnabled 还是 true

正确的顺序
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftButton)
leftButton.isEnabled = false // or navigationItem.leftBarButtonItem?.isEnabled = false
结果 isEnabled 是 false

改变 navigation bar isTranslucent 属性会改变 view 的坐标
放置两个 label。其中, frameLabel 没有添加约束(NSLayoutConstraint),constraintLabel 左、右、下都有约束,与 view 相接。

设置右上角按钮动作
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Change", style: .plain, target: self, action: #selector(rightButtonClicked(_:)))
改变 navigation bar isTranslucent 属性,显示 label 的坐标
@objc private func rightButtonClicked(_ sender: AnyObject) {
navigationController?.navigationBar.isTranslucent = !navigationController!.navigationBar.isTranslucent
updateLabelContent()
}
private func updateLabelContent() {
title = navigationController!.navigationBar.isTranslucent ? "Translecent" : "Opaque"
let frameLabelOrigin = frameLabel.frame.origin
frameLabel.text = "Frame label. x = \(frameLabelOrigin.x), y = \(frameLabelOrigin.y)"
let constraintLabelOrigin = constraintLabel.frame.origin
constraintLabel.text = "Constraint label. x = \(constraintLabelOrigin.x), y = \(constraintLabelOrigin.y)"
print("\(title)")
print("Status bar frame:", UIApplication.shared.statusBarFrame) // (0.0, 0.0, 375.0, 20.0)
print("Navigation bar frame:", navigationController!.navigationBar.frame) // (0.0, 20.0, 375.0, 44.0)
}
通过点击右上角按钮,来查看变化。
透明时

不透明时

View controller 的 view 坐标改变,Status bar 和 navigation bar 的坐标不变

Navigation bar 从不透明变透明,status bar 和 navigation bar 的坐标都不变。整个 view 下移64,高度减小64,不会超出 window。没加约束的 frameLabel 坐标不变,但相对 window 的位置随着 view 一起下移。添加约束的 constraintLabel 的坐标改变,但是相对 window 的位置不变。
如果需要改变 navigation bar isTranslucent 属性,就要考虑对其他 view 会不会有影响,是否使用约束来定位。
转载请注明出处:http://www.cnblogs.com/silence-cnblogs/p/6262471.html
Navigation bar 的注意事项的更多相关文章
- android隐藏底部虚拟键Navigation Bar实现全屏
隐藏底部虚拟键Navigation Bar实现全屏有两种情况 第一种:始终隐藏,触摸屏幕时也不出现 解决办法:同时设置以下两个参数 View.SYSTEM_UI_FLAG_HIDE_NAVIGATIO ...
- 非常不错的Navigation Bar效果
非常不错的Navigation Bar效果,该源码转载于源码天堂的,大家可以了解一下吧,多视图应用程序中,我们常常使用到自定义UINavigationBar来完成导航条的设置. 源码我就不上传了,大家 ...
- HTML5设计网页熔岩灯导航(navigation bar)插件 已经加上完整源代码
导航栏(navigation bar): 1.指位于页眉区域的,在页眉横幅图片上边或下边的一排水平导航按钮,它起着链接博客的各个页面的作用. 2.网页设计中不可缺少的部分,它是指通过一定的技术手段,为 ...
- 与Status Bar和Navigation Bar相关的一些东西
Android Navigation Bar Status Bar 与StatusBar和NavigationBar相关的东西有两种,一是控制它们的显示与隐藏,二是控制它们的透明与否及背景. 在2 ...
- Customizing Navigation Bar and Status Bar
Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest ver ...
- 配置navigation bar外观
/* 配置navigation bar外观开始 */ self.navigationBar.translucent = YES; self.navigationBar.titleTextAttribu ...
- [工作积累] Android: Hide Navigation bar 隐藏导航条
https://developer.android.com/training/system-ui/navigation.html View decorView = getWindow().getDec ...
- nested pop animation can result in corrupted navigation bar
nested pop animation can result in corrupted navigation barFinishing up a navigation transition in a ...
- nested push animation can result in corrupted navigation bar
2013-12-06 10:15:51.668 CodingForFun[4569:70b] nested push animation can result in corrupted navigat ...
随机推荐
- GROUP BY,WHERE,HAVING之间的差别和使用方法
having子句与where有类似之处但也有差别,都是设定条件的语句.在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先运行.而where子句在查询过程中运行优 ...
- java21 封装Response:
封装Response: /** * 封装响应信息 */ public class Response { //两个常量 public static final String CRLF="\r\ ...
- cocos2d-x 开发中的小问题 在xcode4环境下
转自:http://hi.baidu.com/baby_66_/item/302353174f19521cd0d66df2 1.如果你在想怎么去搞定程序的开始运行的背景一闪而过的大图 以及icon想换 ...
- php测试oracle链接是否成功
$conn = oci_connect('eoffice', 'hdujiedian', '//192.168.100.21/hziee'); if (!$conn) { $e = oci_error ...
- PV 并发量的计算
http://blog.csdn.net/xingxing513234072/article/details/17336573 PV与并发之间换算的算法换算公式 并发连接数 = PV / 统计时间 * ...
- ACM——A + B Problem (3)
Home Problems 1086 A + B Problem (3) 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2317 ...
- 【转】【SQLServer】SQL事务用法begin tran,commit tran和rollback tran的用法
Sql Server 2005/2008中提供了begin tran,commit tran和rollback tran来使用事务.begin tran表示开始事务, commit tran表示提交事 ...
- 转载:在Visual Studio 2013中管理中国特色的社会主义Windows Azure
原文链接: http://www.pstips.net/get-azurechinacloud-settings.html 谷歌被豪迈地放弃了中国市场,微软仍旧在中国市场摸爬滚打,跪着挣钱.其中私人定 ...
- UITableView自动滚动方法
1: NSUInteger rowCount = [self.tableView numberOfRowsInSection:0]; NSIndexPath* indexPath = [NSIndex ...
- CocoaPods安装过程中的大坑
一.CocoaPods是什么? CocoaPods是一个用Ruby写的.负责管理iOS项目中第三方开源库的工具,CocoaPods能让我们集中的.统一管理第三方开源库,为我们节省设置和更新第三方开源库 ...