网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Navigationbar的注意事项-创新互联

创新互联公司主营大连网站建设的网络公司,主营网站建设方案,重庆APP软件开发,大连h5小程序设计搭建,大连网站营销推广欢迎大连等地区企业咨询

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 = falsenavigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftButton)

结果 isEnabled 还是 true

Navigation bar 的注意事项

正确的顺序

navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftButton) leftButton.isEnabled = false // or navigationItem.leftBarButtonItem?.isEnabled = false

结果 isEnabled 是 false

Navigation bar 的注意事项

改变 navigation bar isTranslucent 属性会改变 view 的坐标

放置两个 label。其中, frameLabel 没有添加约束(NSLayoutConstraint),constraintLabel 左、右、下都有约束,与 view 相接。

Navigation bar 的注意事项

设置右上角按钮动作

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)}

通过点击右上角按钮,来查看变化。

透明时

Navigation bar 的注意事项

不透明时

Navigation bar 的注意事项

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

Navigation bar 的注意事项

Navigation bar 从不透明变透明,status bar 和 navigation bar 的坐标都不变。整个 view 下移64,高度减小64,不会超出 window。没加约束的 frameLabel 坐标不变,但相对 window 的位置随着 view 一起下移。添加约束的 constraintLabel 的坐标改变,但是相对 window 的位置不变。

如果需要改变 navigation bar isTranslucent 属性,就要考虑对其他 view 会不会有影响,是否使用约束来定位。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:Navigationbar的注意事项-创新互联
网站链接:http://bjjierui.cn/article/cddihs.html

其他资讯