Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Text Editor Crash with Apple Pencil Long Press
We experienced this same crash as of iOS 16 and still in iOS 16.3. Long pressing an Apple Pencil inside a UITextView (instantiated in code) causes Scribble to sometimes insert a long wrapped--almost 2 lines--of blanks, after which there is a short delay and crash with exception "...Inconsistent element cache state...". This crash can be prevented by changing the layout manager of the UITextView from TextKit 2 (now the iOS 16 default) to TextKit 1, which is done strangely enough by simply accessing the UITextView.layoutManager property as described in Apple's source code: // To ensure compatibility with older code, accessing the .layoutManager // of a UITextView - or its .textContainer's .layoutManager - will cause // a UITextView that's using TextKit 2 to 'fall back' to TextKit 1, and // return a newly created NSLayoutManager. After this happens, // .textLayoutManager will return nil - and _any TextKit 2 objects you // may have cached will cease functioning_. Be careful about this if you // are intending to be using TextKit 2! @property(nonatomic, readonly) NSLayoutManager *layoutManager API_AVAILABLE(ios(7.0)); NOTE that this does stop the strange insertion of the extra long blank lines, but instead just makes those blanks vanish when the pencil touches down again.
Feb ’23