4

I'm facing a very strange bug. When I paste anything inside UITextView, I receive a surprising glitch of animation.

To reproduce it I've just created a black .xcodeproj, added UITextView to ViewController via storyboard and ran the application.

The only similiar problem I've found is https://twitter.com/twostraws/status/972914692195790849 And it says that it's a bug of UIKit in iOS11. But there lot of applications on my iPhone with UITextview that works correctly on iOS11. You can see the bug in the video here – https://twitter.com/twostraws/status/972914692195790849

Any suggestions or help would be appreciated. What I tried? - Tried the new clear project with minimal changes; - Disabled all the autocorrection types; - Removed constraints; - Tried on several iPhones with different version – 11.2.5 and 11.4.2.

The original project is attached. It's made on Swift 4.1 with Xcode 9.4(9F1027a) https://ufile.io/fzyj8

katleta3000
  • 2,484
  • 1
  • 18
  • 23

1 Answers1

8

I checked some other applications on my iPhone like Todoist and found the same bug there. But also I've found the solution. I hope Apple will urgently fix this bug.

So you may implement the UITextPasteDelegate and disabled the animation on paste action. This API is available only iOS11+, but it seems that the bug is also reproduced only on iOS11.

class ViewController: UIViewController {

    @IBOutlet weak var textView: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()
        textView.pasteDelegate = self
    }
}

extension ViewController: UITextPasteDelegate {
    func textPasteConfigurationSupporting(_ textPasteConfigurationSupporting: UITextPasteConfigurationSupporting, shouldAnimatePasteOf attributedString: NSAttributedString, to textRange: UITextRange) -> Bool {
        return false
    }
}
katleta3000
  • 2,484
  • 1
  • 18
  • 23
  • 3
    Thank you so much for finding this. This issue has been driving me crazy for a while. In my tests (before realising the existence of the UITextPasteDelegate option) the animation seemed more ok when working with a standard UITextView compared to more complicated use cases of UITextView (supporting resizing for keyboard appearance, responding to text events etc). I am still wondering of the underlying cause for the incorrect animation is a missing super call somewhere which leads to issues when iOS is taking a snapshot for the animation. – solesignal Aug 14 '18 at 02:16
  • 2
    @solesignal I'm wondering too. I'll keep monitoring new iOS versions. Hope not to forget to write back here when the bug is fixed. – katleta3000 Aug 14 '18 at 12:47
  • I see it too, in iOS 12. Wondering if it's an issue on my end or if it's still a bug in UIKit – jcharch Sep 18 '19 at 17:50
  • This issue is resolved in iOS 13 but still existed in lower versions. Thanks for this amazing solution! – JsW Apr 07 '20 at 09:15