问题
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
回答1:
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
}
}
来源:https://stackoverflow.com/questions/51770900/uitextview-stange-animation-glitch-on-paste-action-ios11