【发布时间】:2017-07-17 21:30:20
【问题描述】:
我正在尝试实现这个image of my implementation。
uilabel 下方的三个按钮是可点击的。我有一个 UIView 作为我的自定义导航栏视图的子视图,然后在该视图中有两个视图,一个是 uilabel,第二个是 uibuttons 的 uiview i
我已经尝试从其他答案中实施解决方案,例如
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)
}
但这没有用。我注意到,如果我点击默认导航栏大小位置附近的按钮上方,那么点击就会被识别。
如果有帮助的话,我的导航栏的大小是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()
【问题讨论】:
标签: ios swift uinavigationbar