Handle navigation bar click issues

dev
wenlei 10 months ago
parent 3a3794d868
commit 5ae77f63ab

@ -7,24 +7,15 @@
import Foundation
protocol NavigationBarTouchDelegate: AnyObject {
func navigationBar(_ navigationBar: NavigationBar, hitTest point: CGPoint, with event: UIEvent?)
}
class NavigationBar: UINavigationBar {
weak var touchDelegate: NavigationBarTouchDelegate?
private var isHitTestHandled = false
weak var passthroughView: UIView?
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let playButtonPoint = convert(point, to: self)
if self.point(inside: playButtonPoint, with: event) && !isHitTestHandled {
isHitTestHandled = true
touchDelegate?.navigationBar(self, hitTest: point, with: event)
DispatchQueue.main.async {
self.isHitTestHandled = false
}
return self
let navPoint = convert(point, to: self)
if let passthroughView = passthroughView, self.point(inside: navPoint, with: event) {
return passthroughView.hitTest(convert(point, to: passthroughView), with: event)
}
return super.hitTest(point, with: event)
}
@ -32,12 +23,11 @@ class NavigationBar: UINavigationBar {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

@ -63,6 +63,10 @@ class NavigationController: UINavigationController {
appearance.shadowColor = .clear
// if let navigationBar = navigationBar as? NavigationBar {
// navigationItem.titleView = navigationBar.titleView
// }
}

@ -620,3 +620,5 @@ class HomePagerView: UIView {
}

@ -14,9 +14,6 @@ import Kingfisher
import ETNavBarTransparent
class HomeViewController: TableViewController {
var homePagerView: HomePagerView = {
let homePagerView = HomePagerView.init()
@ -33,10 +30,7 @@ class HomeViewController: TableViewController {
navigationItem.title = "期刊推荐"
if let navigationBar = self.navigationController?.navigationBar as? NavigationBar {
navigationBar.touchDelegate = self
}
}
@ -52,6 +46,18 @@ class HomeViewController: TableViewController {
tabbar.showAllBar(true, animated: true)
}
if let navigationBar = self.navigationController?.navigationBar as? NavigationBar {
navigationBar.passthroughView = homePagerView
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if let navigationBar = self.navigationController?.navigationBar as? NavigationBar {
navigationBar.passthroughView = nil
}
}
override func makeUI() {
@ -101,8 +107,6 @@ class HomeViewController: TableViewController {
self?.navigator.show(segue: .journalDetail(viewModel: journalDetailViewModel), sender: self)
default: break
}
}.disposed(by: rx.disposeBag)
@ -160,6 +164,7 @@ class HomeViewController: TableViewController {
}
func updateNav(navBarBgAlpha: CGFloat) {
self.navBarBgAlpha = navBarBgAlpha
self.currentNavBarBgAlpha = navBarBgAlpha
// UINavigationBarAppearance
@ -273,7 +278,7 @@ extension HomeViewController {
}
extension HomeViewController: NavigationBarTouchDelegate {
extension HomeViewController {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
var delta = scrollView.contentOffset.y / CGFloat(BaseDimensions.topHeight)
delta = CGFloat.maximum(delta, 0)
@ -282,16 +287,4 @@ extension HomeViewController: NavigationBarTouchDelegate {
}
func navigationBar(_ navigationBar: NavigationBar, hitTest point: CGPoint, with event: UIEvent?) {
let pagerViewPoint = view.convert(point, to: homePagerView)
if homePagerView.point(inside: pagerViewPoint, with: event) {
homePagerView.pagerView.selectItem(at: homePagerView.pagerView.currentIndex, animated: true)
homePagerView.pagerView.delegate?.pagerView?(homePagerView.pagerView, didHighlightItemAt: homePagerView.pagerView.currentIndex)
homePagerView.pagerView.delegate?.pagerView?(homePagerView.pagerView, didSelectItemAt: homePagerView.pagerView.currentIndex)
}
print("导航栏点击")
}
}

Loading…
Cancel
Save