主要方法:
func findNavBarHarLineImageView(v: UIView) -> UIView? {
if v.isKind(of: UIImageView.self) && v.bounds.size.height <= 1 {
return v
}
for subview in v.subviews {
if let img = findNavBarHarLineImageView(v: subview) {
return img
}
}
return nil
}
1、定义一个视图:
var navBarHairlineImageView: UIView?
2、在控制器创建时指定这个视图
override func viewDidLoad() {
super.viewDidLoad()
navBarHairlineImageView = findNavBarHarLineImageView(v: (navigationController?.navigationBar)!)
}
3、在viewWillAppear方法中隐藏:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navBarHairlineImageView?.isHidden = true
}
4、在viewDidDisappear方法中恢复显示:
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
navBarHairlineImageView?.isHidden = false
}
网友评论