'Is it possible to prevent UIMenuController from being dismissed when one of it's UIMenuItems is selected?
The default behaviour is that selecting an item will dismiss the menu. I see that some Apple's apps have items which will do some action but keep the menu open.
For example in Notes, there is Indent item which will indent the text but keep the menu open.
Is it possible to achieve this with the public API?
Solution 1:[1]
Overrider the selectedRange
, it works for me.
class YourTextView: UITextView {
private var isTextUpdating: Bool = false
override var attributedText: NSAttributedString! {
willSet {
isTextUpdating = true
}
didSet {
isTextUpdating = false
}
}
override var selectedRange: NSRange {
set {
if !isTextUpdating {
super.selectedRange = newValue
}
}
get {
return super.selectedRange
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | nathanwhy |