0
votes

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)
}

enter image description here 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?

1
Just add another tap gesture to bubble view which dismiss the menu if the menu is visibleE.Coms
What must be happening is, when you tap outside, it must be again registering a touch for your bubble view, and showing the menu. this is just a guess, try adding log when you create menu.. and if this is the case, you can create a strong var, and then check if the menu already exist, before showing it.AjinkyaSharma

1 Answers

0
votes

It seems that the UIMenuController's rect is too big in width. You can check this with a breakpoint and see its frame or set the menu background colour to eg.red and see.