当前位置:首页 > 通信资讯 > 正文

navigation bar是什么意思(navigation-bar)

bar button item 使用 button 作为 custom view,初始化 isenabled 为 false,注意顺序

需要设置 bar button item 的 custom view 为 button,但一开始 isenabled 要为 false。

生成一个 button

?
1 2 3 4 5 6 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

?
1 2 leftbutton.isenabled = false navigationitem.leftbarbuttonitem = uibarbuttonitem(customview: leftbutton)

结果 isenabled 还是 true

navigation bar是什么意思(navigation-bar)

正确的顺序

?
1 2 navigationitem.leftbarbuttonitem = uibarbuttonitem(customview: leftbutton) leftbutton.isenabled = false // or navigationitem.leftbarbuttonitem?.isenabled = false

结果 isenabled 是 false

navigation bar是什么意思(navigation-bar)

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

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

navigation bar是什么意思(navigation-bar)

设置右上角按钮动作

?
1 navigationitem.rightbarbuttonitem = uibarbuttonitem(title: "change", style: .plain, target: self, action: #selector(rightbuttonclicked(_:)))

改变 navigation bar istranslucent 属性,显示 label 的坐标

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 @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)

不透明时

navigation bar是什么意思(navigation-bar)

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

navigation 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

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。