我正在尝试执行此image of my implementation。自定义导航栏在整个视图中不会收到触摸事件
其中uilabel下面的三个按钮是可点击的。我有一个UIView的是我的自定义导航栏视图的子视图,则该视图中的两个观点,一个是的UILabel,第二个是我
我试着从实施其他答案解决方案,如
uibuttons的UIView的override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.point(inside: point, with: event) {
self.isUserInteractionEnabled = true
}else{
self.isUserInteractionEnabled = false
}
return super.hitTest(point, with: event)
}
但这没有奏效。我注意到,如果我点击靠近默认uinavigation栏大小的位置上方的按钮,则会识别出水龙头。
如果有帮助,我的导航栏的大小是CGSize(width: self.frame.size.width, height: 100)
。
更新
只是增加我的自定义导航类,它的用法
class CustomNavigationBar: UINavigationBar {
override func sizeThatFits(_ size: CGSize) -> CGSize {
let newSize :CGSize = CGSize(width: self.frame.size.width, height: 100)
return newSize
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.point(inside: point, with: event) {
self.isUserInteractionEnabled = true
}else{
self.isUserInteractionEnabled = false
}
return super.hitTest(point, with: event)
}
}
let navigationController = UINavigationController(navigationBarClass: CustomNavigationBar.self, toolbarClass: nil)
navigationController.setViewControllers([mainController], animated: false)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
嘿Manikanta,我试过你的建议,但没有奏效。 –
你可以请分享你自定义导航栏的代码。 –
我已经用我的自定义类更新了我的问题以及我如何使用它。 –