Quantcast
Viewing all articles
Browse latest Browse all 14

Answer by vegadodo for How to know when text is pasted into a UITextView?

Building on Alexey Saechnikov's answer, if you're targeting iOS 16+, you could also use a new API.

/** * @abstract Called when the text field is about to dismiss the edit menu. * * @param textField    The text field displaying the menu. * @param animator      Dismissal animator. Add animations to this object to run them alongside the dismissal transition. */@available(iOS 16.0, *)optional func textField(_ textField: UITextField, willDismissEditMenuWith animator: any UIEditMenuInteractionAnimating)
var isPasting: Bool = false// subclass UITextFieldoverride func paste(_ sender: Any?) {    isPasting = true    super.paste(sender)}// in UITextFieldDelegatefunc textField(_ textField: UITextField, willDismissEditMenuWith animator: any UIEditMenuInteractionAnimating) {    if isPasting {        // user has pasted        // implement whatever you want        isPasting = false // toggle back    }}

Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>