本文介绍了导航栏 + 搜索控制器 + 大标题:滚动时的细线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
上下文:
UINavigationController
带有UITableViewController
UISearchController
在导航栏中- 半透明黑色导航栏,使用大标题,
tintColor
,barTintColor
(所以没有背景图片).
UINavigationController
with aUITableViewController
UISearchController
in the navigation bar- Navigation bar translucent with black style, it uses large title,
tintColor
,barTintColor
(so no background image).
问题:
我有一个奇怪的动画故障,在搜索栏上方显示一条细线.细线仅在滚动期间出现.
I have a strange animation glitch that shows a hairline above the search bar. The hairline appears only during the scroll.
针对类似问题,我已经尝试了很多解决方案,但都没有帮助.
I have already tried many solutions concerning similar problems, but they have not helped.
在装有 iOS 12.1.3 的 iPhone 7 上测试
Tested with an iPhone 7 with iOS 12.1.3
推荐答案
您可以使用此解决发际线问题
You can fix hairline issue using this
searchController.searchBar.layer.borderColor = UIColor(red: 242/255.0, green: 82/255.0, blue: 46/255.0, alpha: 1).CGColor
searchController.searchBar.layer.borderWidth = 1
如果上述方法不起作用.你可以完全去除发际线
if the above didn’t work. you can remove the hairline completely
extension UINavigationBar {
func hideBottomHairline() {
self.hairlineImageView?.isHidden = true
}
func showBottomHairline() {
self.hairlineImageView?.isHidden = false
}
}
extension UIView {
fileprivate var hairlineImageView: UIImageView? {
return hairlineImageView(in: self)
}
fileprivate func hairlineImageView(in view: UIView) -> UIImageView? {
if let imageView = view as? UIImageView, imageView.bounds.height <= 1.0 {
return imageView
}
for subview in view.subviews {
if let imageView = self.hairlineImageView(in: subview) { return imageView }
}
return nil
}
}
这篇关于导航栏 + 搜索控制器 + 大标题:滚动时的细线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!