How can I get rid of the flickering/blinking of UIMenuItems in a UIMenuController? I currently have copy and paste items, but when my app displays the menu inside the action of a UILongPressGestureRecognizer, they start blinking.
@objc func viewLongPressed(_ recognizer: UILongPressGestureRecognizer) {
[...]
UIMenuController.shared.setMenuVisible(true, animated: true)
}
Are there any implementations for this in iOS?
This is because
UILongPressGestureRecognizerevents get recognized constantly if you keep pressing the recognizer view. Calling thesetMenuVisible(animated:)method ofUIMenuControllerrepeatedly causes the blinking effect you've described.To solve this, show the menu only if the state of the recognizer is
.began.