I have a UITableViewCell
with a subview inside bubbleView
. I have added a UIMenuController like so:
override func awakeFromNib() {
super.awakeFromNib()
bubbleView.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(presentMenu)))
}
@objc private func presentMenu() {
let menu = UIMenuController.shared
becomeFirstResponder()
menu.setTargetRect(bubbleView.bounds, in: bubbleView)
menu.setMenuVisible(true, animated: true)
}
This works when presenting however if I tap to the rhs of the bubble the menu will not dismiss, i.e. it will not dismissed if the same cell it is presenting from is tapped. Tapping below or above dismisses the menu. What am I doing wrong here? How can I get it to dismiss if tapped on the right hand side?