无法在右侧处理UIBarButtonItem上的点击

时间:2016-12-05 23:20:18

标签: uinavigationbar uibarbuttonitem

我无法在右侧点击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)

1 个答案:

答案 0 :(得分:0)

hamburgerView的设置框架解决了这个问题。

hamburgerView.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)

为什么左右之间存在差异,我不知道。