Navigation bar + Search controller + Large title: Hairline during scrolling

做~自己de王妃 提交于 2019-12-11 18:35:31

问题


Context:

  • UINavigationController with a UITableViewController
  • UISearchController in the navigation bar
  • Navigation bar translucent with black style, it uses large title, tintColor, barTintColor (so no background image).

Issue:

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.

Tested with an iPhone 7 with iOS 12.1.3


回答1:


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


来源:https://stackoverflow.com/questions/54504586/navigation-bar-search-controller-large-title-hairline-during-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!