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