我无法在右侧点击UIBarButtonItem。
hamburgerView = HamburgerIcon()
hamburgerView.userInteractionEnabled = true
hamburgerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hamburgerIconClicked)))
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: hamburgerView)
但是当我在左侧使用此按钮时,一切正常。
hamburgerView = HamburgerIcon()
hamburgerView.userInteractionEnabled = true
hamburgerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hamburgerIconClicked)))
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: hamburgerView)
答案 0 :(得分:0)
hamburgerView
的设置框架解决了这个问题。
hamburgerView.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
为什么左右之间存在差异,我不知道。