Manage text storage and perform custom layout of text-based content in your app's views using TextKit.

Posts under TextKit tag

176 Posts

Post

Replies

Boosts

Views

Activity

Noticeable delay before keyboard appears
Ever since using Xcode 14 SDK to compile, the iOS keyboard takes a long, variable, time to appear when focusing a UITextField or UITextView. I can confirm that using the previous SDK, the notification keyboardWillShow fires instantly, while in the current 14 SDK it takes a considerable amount of time, and not just the first time the keyboard opens. It always dismisses instantly. Is there any way to make the keyboard appear more quickly? Sometimes UI needs to move in sync with the keyboard and we need to know the keyboard height ASAP so it doesn't feel delayed. Even without needing the notification sooner, my app feels more delayed in general since selecting a text view takes longer for the keyboard to appear. Is there any way to debug why, or speed this up? It seems in the Notes app the keyboard appears instantly.
1
0
1.9k
Jan ’23
SwiftUI TextEditor performance issues
Has anyone used the new SwiftUI 2.0 TextEditor with a sizeable string? I'm currently trying it with a 400K text string and typing into the TextEditor horribly slow. Each letter I type takes seconds to appear. When the text size is small (say just a few thousand characters) it's fast - so it's clearly something to do with performance. Is this a known issue? Should I be doing something to improve it? PS - I do need to use it for my app (for e.g., a Markdown editor that loads a large file)  if let t = try? String(contentsOfFile: filePathName, encoding: .utf8) {             editorText = t             Config.logger.debug("EditorView.onAppear: Read text count = \(t.count) characters")             }
4
0
3.2k
Dec ’22
TextEdit Behaving Odd on Big Sur Update
Hi, I'm an avid user of TextEdit to keep track of my thoughts and To-Do's through my work day. The result is, I end up with a fairly long text file, but not big on size in terms of storage. After updating to Big Sur 11.0.1, I'm noticing an odd behaviour. When every I press [Delete] more than thrice, the scroll bar jumps to the top of the text, i.e. the first line in the text file. This is very frustrating, especially, when you have lot of text and it scrolls all the way to the top. The only solution I have found is to press [Delete] slowly (may be one character per second) to avoid the scroll bar jumping to the first line of the text file. Also noticed, it does not happen in a full sentence, but only when when there's a short word and a line break [Enter] above and below the word. I'm continuing with the same file I had saved on Catalina and never had this issue. Looks like a bug to me. [PS: I am a user experience designer, not a developer and only have minimal knowledge of coding. ] Thanks, Anish
68
2
17k
Nov ’22
From IOS 16 onwards my app which uses UITextView in iOS for editing, started crashing for a number of users with error
App crashes with error "Fatal Exception: NSInvalidArgumentException -[<NSTextContentStorage: 0x281dc68a0> locationFromLocation:withOffset:] received invalid location (null)" **After researching we found that this could be an issue with the new textkit engine of UITextView. And to restore the previous behavior and avoid the crash, we explicitly set the UITextView to use TextKit 1. But unfortunately, even after this change, this crash is not gone and users are still facing this issue. I'm also adding complete stack trace of this crash Fatal Exception: NSInvalidArgumentException 0 CoreFoundation        0x9e88 __exceptionPreprocess 1 libobjc.A.dylib        0x178d8 objc_exception_throw 2 CoreFoundation        0xf9c58 __CFDictionaryCreateGeneric 3 UIFoundation         0x220e0 -[NSTextContentStorage locationFromLocation:withOffset:] 4 UIFoundation         0x9f104 -[NSTextLineFragment textLineFragmentRange] 5 UIFoundation         0x86e70 __95-[NSTextLayoutManager _copyTextLineFragmentRangeForPoint:inContainerAtLocation:pointPlacement:]_block_invoke 6 CoreFoundation        0xa3a0 NSARRAY_IS_CALLING_OUT_TO_A_BLOCK 7 CoreFoundation        0x910e0 -[__NSArrayI  enumerateObjectsWithOptions:usingBlock:] 8 UIFoundation         0x86cfc -[NSTextLayoutManager _copyTextLineFragmentRangeForPoint:inContainerAtLocation:pointPlacement:] 9 UIFoundation         0x86eb4 -[NSTextLayoutManager lineFragmentRangeForPoint:inContainerAtLocation:] 10 UIFoundation         0x7e6ec -[NSTextSelectionNavigation _lineFragmentInfoForPoint:inContainerAtLocation:bounds:layoutOrientation:beforeLineFragment:afterLineFragment:lineFragmentRange:] 11 UIFoundation         0x815d8 -[NSTextSelectionNavigation textSelectionsInteractingAtPoint:inContainerAtLocation:anchors:modifiers:selecting:bounds:] 12 UIKitCore           0x98f5d8 -[_UITextKit2LayoutController cursorPositionAtPoint:inContainer:] 13 UIKitCore           0xf33d88 -[UITextInputController _characterPositionForPoint:] 14 UIKitCore           0xf4a2cc -[UITextView closestPositionToPoint:] 15 UIKitCore           0xedef5c -[UITextSelectionInteraction tappedToPositionCursorWithGesture:atPoint:granularity:completionHandler:] 16 UIKitCore           0xedecc8 -[UITextSelectionInteraction _checkForRepeatedTap:gestureLocationOut:] 17 UIKitCore           0xedf524 -[UITextSelectionInteraction _handleMultiTapGesture:] 18 UIKitCore           0x24ed54 -[UIApplication sendAction:to:from:forEvent:] 19 UIKitCore           0x9448fc -[UITextMultiTapRecognizer onStateUpdate:] 20 UIKitCore           0xbe874 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] 21 UIKitCore           0x42c9f0 _UIGestureRecognizerSendTargetActions 22 UIKitCore           0x1a60a4 _UIGestureRecognizerSendActions 23 UIKitCore           0x86a14 -[UIGestureRecognizer _updateGestureForActiveEvents] 24 UIKitCore           0x1328d8 _UIGestureEnvironmentUpdate 25 UIKitCore           0x9b7e14 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] 26 UIKitCore           0xf731c -[UIGestureEnvironment _updateForEvent:window:] 27 UIKitCore           0xfbc74 -[UIWindow sendEvent:] 28 UIKitCore           0xfaf44 -[UIApplication sendEvent:] 29 Aspen             0x6963c0 TimerApplication.sendEvent(_:) () 30 Aspen             0x696834 @objc TimerApplication.sendEvent(_:) () 31 UIKitCore           0xfa600 __dispatchPreprocessedEventFromEventQueue Also, the app was re-released in Appstore with Xcode 14.0. Any help would be appreciated.
1
0
1.3k
Nov ’22
UITextView crash iOS 16.2 beta1 & beta2
The code has been working for serval years. now it crashes when running on iOS 16.2 beta1 & beta2 UITextView *text = [[UITextView alloc] init]; text.attributedText = attributedText; text.frame = CGRectZero; text.editable = NO; text.scrollEnabled = NO; text.clipsToBounds = NO; text.showsVerticalScrollIndicator = NO; text.showsHorizontalScrollIndicator = NO; text.textContainer.lineFragmentPadding = 0; text.textContainerInset = UIEdgeInsetsZero; text.contentInset = UIEdgeInsetsZero; text.tag = index; [self addSubview:text]; crash log Last Exception Backtrace: 0 CoreFoundation 0x1b9849e88 __exceptionPreprocess + 164 1 libobjc.A.dylib 0x1b2b5b8d8 objc_exception_throw + 60 2 CoreFoundation 0x1b9939c58 __CFDictionaryCreateGeneric + 0 3 UIFoundation 0x1c3c937f4 -[NSCountableTextLocation compare:] + 204 4 UIFoundation 0x1c3d0d3fc -[NSTextRange textRangeByIntersectingWithTextRange:] + 144 iPhone OS 16.2 (20C5032e).crash the system is upgraded to iPhone OS 16.2 (20C5043e) from iPhone OS 16.2 (20C5032e) ,it also crash iPhone OS 16.2 (20C5043e).crash Guess it may be caused by the upgrade from TextKit1 to TextKit2. // 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)); then call layoutManager,'fall back' to TextKit 1, it work! can I ask the question,What is the cause of the problem? can it be fixed on the 16.2 beta3 or release version? Thank you very much!
1
0
1.6k
Nov ’22
The problem that specific character height and spacing 0 cannot be set using NSMutableAttributedString
We are adding a function to change the height and spacing of only certain characters (NewLine) using NSMutableAttributedString. Set font size to 0 and lineSpacing to 0. For characters other than specific characters, enter the font size and lineSpacing separately. (e.g. font size = 28.0 / lineSpacing = 16.0) When applied to UITextView , the space in that part is higher than the lineSpacing set for other lines. (In other words, I set the font size and linespace to 0 for a blank line, but the height occurs in the blank line.) I thought that by setting the font size and lineSpacing to 0, the line height would be 0. But it doesn't appear that way. Does anyone know of this issue? If there is something I don't understand, please let me know, it will help me to solve it. The iOS version is being developed in the 16.1 environment.
0
0
1.1k
Oct ’22
Has anyone solved the UITableView text persistence or overlapping issue in iOS 16.1 iPhone 14 Pro and 14 Pro Max?
Has anyone solved the UITableView text persistence or overlapping issue in iOS 16.1 iPhone 14 Pro and 14 Pro Max? If anyone has solved the problem by modifying the code, please reply. I posted on the forum a while ago and forwarded the issue to Apple Feedback. Link to the forum post: https://developer.apple.com/forums/thread/718401 (Sample code and video links are in the article above.) However, it was confirmed today that iOS 16.1 did not improve on the iPhone 14 Pro Max. After making the cell of UITableView display text with UITextView or UILabel The text color is set to black and the background to white. (The afterimage is displayed in black, so it must be reproduced with a white background.) UITableView srollToRow Calls the next or previous Row in the current Row without any animation effects as shown in the code below. tableView!.scrollToRow(at: IndexPath(row: self.pIndex, section: 0), at: .top, animated: false) And the call to scrollToRow is UITapGestureRecognizer , which makes it scroll one page at a time when the user taps. At this time, the cell height of UITableView is set to the total height of the device. This will briefly display the text content that was just previously displayed in black. (Sometimes it is displayed a little longer.) So the current page text and the previous page text overlap. There is a phenomenon that the contents of the previous page disappear. In a slightly animated effect, it feels like a transition to the next page, leaving an afterimage of the previous page content. But I didn't add any animation effects in the motion. This is definitely happening on the iPhone 14 Pro and 14 Pro Max. We think it might be an iOS error. I don't think it will be improved as iOS will be updated soon. (No feedback from Apple as of today.) So, if you have experienced the same problem and solved it through code, please help. Even if it is improved with an OS update in the future, there are users who are currently uncomfortable, so if there is a way, I am thinking of including it in the app update.
1
0
1.4k
Oct ’22
NSTextField not showing attributed string
I am trying to create a simple NSTextField where the entire text content should be a link. The text field is created/positioned in Interface Builder and later propagated with actual data by the view controller. However, the text field does not display my attributed string. In order to keep things neat and tidy, I subclassed NSTextField like so: public class MyLink: NSTextField {     private var linkRange: NSRange?     override init(frame frameRect: NSRect) {         super.init(frame: frameRect)     }     required init?(coder: NSCoder) {         super.init(coder: coder)     }     public func setLinkContent(text: String, to url: URL, range: NSRange?) {         allowsEditingTextAttributes = true         isSelectable = true         let attributedLink = NSMutableAttributedString(string: text)         self.linkRange = range ?? NSRange(location: 0, length: text.count)         attributedLink.addAttribute(.link, value: url, range: self.linkRange!)         attributedLink.addAttributes([             .foregroundColor: NSColor.red,             .underlineStyle: NSUnderlineStyle.single,             .cursor: NSCursor.pointingHand,             .font: NSFont.systemFont(ofSize: 16)         ], range: self.linkRange!)         self.attributedStringValue = attributedLink     } } To put things in perspective, the view controller calls setLinkContent to propagate the text field data. And after that - nothing (see image). You see that the text field is there because of the blue background color I set, but the actual text is not propagated. Configuration of the TextField in IB:
0
1
1.2k
Oct ’22
How do I get the value of UITextField text instance property and update UITableView row whenever the user edits the UITextField text property?
0 How would I update a table view row as as a text field text changes? It is difficult to create a string from the arguments in textField(:shouldChangeCharactersIn:replacementString:) so that the string I create would be equal to the string value of the text property of the text field after the textField(:shouldChangeCharactersIn:replacementString:) occurs. Is there a way to use the UITextInput protocol of UITextField? I haven't found anything on stackoverflow about using the UITextInput protocol of UITextField except a question in 2012 using Objective-C that asks why he's getting a crash.
3
0
1.5k
Oct ’22
TextKit2 Multi Column Layout
I'm trying to implement a multi column layout for a hex editor using TextKit2. I'm using the sample App named "LayoutTextWithTextKit2" as my starting point, but I'm struggling to understand what the best approach could be to implement it. My doubts are: Is it a good idea to use a text element for a single line in a single column? I'm basing my text element on NSTextParagraph. Following my previous question, is there any way to layout these text elements horizontally in a single line, instead of having the layout engine automatically lay them out in a vertical stack? Where is the correct location where I can override the positioning for each text element manually if I wanted to not base my elements in NSTextParagraph? Would this be a good idea? I apologize for the many questions, but my basic problem is that it's not clear to me if I'm missing something that's obvious, and there's a simple way to address my troubles. Any guidance towards that goal, even beyond my questions above, will be appreciated. I'm attaching an image showing two fragments that I'd like to be laid out horizontally in the same line, for reference.
0
0
1.2k
Sep ’22
UITextView iOS16 - access to layoutManager property of textview cause crash
The code has been working for serval years. now it crashes when running on iOS 16 and on the layoutManager = textView.layoutManager . It seems the TextKit 1 compatibility mode became active, but it still crashes on some of the textView if the first word is Arabic. static func didTapTerm(_ sender: UITapGestureRecognizer) -> String? {   guard let senderView = sender.view, (senderView is UITextView) else {     return nil   }   let textView = senderView as! UITextView,   layoutManager = textView.layoutManager       var location = sender.location(in: textView)   location.x -= textView.textContainerInset.left   location.y -= textView.textContainerInset.top       // find the value   // character index at tap location   let textContainer = textView.textContainer,   characterIndex = layoutManager.characterIndex(for: location, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil),   textStorage = textView.textStorage       guard characterIndex < textStorage.length else {     return nil   }       var range = NSRange()   if let phrase = textStorage.attribute(customAttributedStringKey,                    at: characterIndex,                    effectiveRange: &range) {     if let ph = phrase as? String {       // update UI ...     }     return phrase as? String   }   return nil } This is a console log: 2022-09-15 13:29:55.532693-0700 DictionaryApp[1101:95240] [Text] UITextView 0x1051cd600 is switching to TextKit 1 compatibility mode because its layoutManager was accessed. Break on void _UITextViewEnablingCompatibilityMode(UITextView *__strong, BOOL) to debug. 2022-09-15 13:29:55.543047-0700 DictionaryApp[1101:95240] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange invalid char range 1 2022-09-15 13:29:55.543166-0700 DictionaryApp[1101:95240] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange character count mismatch 2022-09-15 13:32:06.118905-0700 DictionaryApp[1101:95240] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range {5, 99} out of bounds; string length 103' *** First throw call stack: (0x1ab8f2248 0x1a4cbfa68 0x1a5d7c484 0x1b5b42260 0x1b5b5710c 0x1b5b55a14 0x1b5b73a20 0x1b5b73924 0x1b5b44df4 0x1b5b43cf4 0x1b5b639c0 0x1b5b61b08 0x1b5b61778 0x1b5b6125c 0x1ae9adcc4 0x1adaa76d0 0x1ae9ada3c 0x1adb8bfa0 0x1025ce384 0x102474d9c 0x102475154 0x1adb35164 0x1adea2dfc 0x1adc1cb94 0x1adafd1dc 0x1adba9358 0x1ae42a1d8 0x1adb6dd18 0x1adb72674 0x1adb71944 0x1adb71000 0x1adbb8d64 0x1adec14dc 0x1ab9be22c 0x1ab9ca614 0x1ab94e51c 0x1ab963eb8 0x1ab9691e4 0x1e4789368 0x1ade18d88 0x1ade189ec 0x102661fb0 0x1c9c8d948) libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range {5, 99} out of bounds; string length 103' terminating with uncaught exception of type NSException This is the backtrace:
0
4
2.1k
Sep ’22
How to achieve NSSharingService menu options for NSTextAttachments inside UITextView in MacCatalyst?
When I hover the mouse over the NSTextAttachment image inside the UITextview, it should show this option to MarkUp. All native app including Notes, TextEditor, Mail have this behaviour: I think, by default, NSTextView will show the NSSharingServicePicker button when you hover over an image inside the text view. That’s true even for custom image-based NSTextAttachments in the attributed string. But it is not showing the button for UITextview in MacCatalyst. Also NSSharingService class is limited to MacOS only. Are there any alternative way to achieve this in MacCatalyst?
0
0
1.2k
Jul ’22
UITextView + TextKit 2: Are we allowed to configure our own custom rendering surface when using UITextView?
Hi TextKit 2 Team, I'm trying to configure my own custom rendering surface when using UITextView(usingTextLayoutManager: true). What I'm currently doing is adding a "contentLayer: CALayer" into my UITextView and adding my rendering surfaces into that. The issue I'm running into, is that the rendering surface will display the first character I input, but then will not update for subsequent text until: It becomes long enough to cause a line wrap. I hit return. Not sure if I'm doing something wrong? So my questions are: Is using configureRenderingSurface API intended to be used when I'm using UITextView? Or it's only meant for when I do fully custom InputView? Should I be inserting my rendering surfaces into my contentLayer or is there some more appropriate place for me to insert into? How do I properly trigger redraw or invalidation of my rendering surface on text editing changes? Is this a bug or do I have to trigger an update manually somewhere? Many thanks in advance!
0
0
1.4k
Jun ’22
Noticeable delay before keyboard appears
Ever since using Xcode 14 SDK to compile, the iOS keyboard takes a long, variable, time to appear when focusing a UITextField or UITextView. I can confirm that using the previous SDK, the notification keyboardWillShow fires instantly, while in the current 14 SDK it takes a considerable amount of time, and not just the first time the keyboard opens. It always dismisses instantly. Is there any way to make the keyboard appear more quickly? Sometimes UI needs to move in sync with the keyboard and we need to know the keyboard height ASAP so it doesn't feel delayed. Even without needing the notification sooner, my app feels more delayed in general since selecting a text view takes longer for the keyboard to appear. Is there any way to debug why, or speed this up? It seems in the Notes app the keyboard appears instantly.
Replies
1
Boosts
0
Views
1.9k
Activity
Jan ’23
SwiftUI TextEditor performance issues
Has anyone used the new SwiftUI 2.0 TextEditor with a sizeable string? I'm currently trying it with a 400K text string and typing into the TextEditor horribly slow. Each letter I type takes seconds to appear. When the text size is small (say just a few thousand characters) it's fast - so it's clearly something to do with performance. Is this a known issue? Should I be doing something to improve it? PS - I do need to use it for my app (for e.g., a Markdown editor that loads a large file)  if let t = try? String(contentsOfFile: filePathName, encoding: .utf8) {             editorText = t             Config.logger.debug("EditorView.onAppear: Read text count = \(t.count) characters")             }
Replies
4
Boosts
0
Views
3.2k
Activity
Dec ’22
TextEdit Behaving Odd on Big Sur Update
Hi, I'm an avid user of TextEdit to keep track of my thoughts and To-Do's through my work day. The result is, I end up with a fairly long text file, but not big on size in terms of storage. After updating to Big Sur 11.0.1, I'm noticing an odd behaviour. When every I press [Delete] more than thrice, the scroll bar jumps to the top of the text, i.e. the first line in the text file. This is very frustrating, especially, when you have lot of text and it scrolls all the way to the top. The only solution I have found is to press [Delete] slowly (may be one character per second) to avoid the scroll bar jumping to the first line of the text file. Also noticed, it does not happen in a full sentence, but only when when there's a short word and a line break [Enter] above and below the word. I'm continuing with the same file I had saved on Catalina and never had this issue. Looks like a bug to me. [PS: I am a user experience designer, not a developer and only have minimal knowledge of coding. ] Thanks, Anish
Replies
68
Boosts
2
Views
17k
Activity
Nov ’22
From IOS 16 onwards my app which uses UITextView in iOS for editing, started crashing for a number of users with error
App crashes with error "Fatal Exception: NSInvalidArgumentException -[<NSTextContentStorage: 0x281dc68a0> locationFromLocation:withOffset:] received invalid location (null)" **After researching we found that this could be an issue with the new textkit engine of UITextView. And to restore the previous behavior and avoid the crash, we explicitly set the UITextView to use TextKit 1. But unfortunately, even after this change, this crash is not gone and users are still facing this issue. I'm also adding complete stack trace of this crash Fatal Exception: NSInvalidArgumentException 0 CoreFoundation        0x9e88 __exceptionPreprocess 1 libobjc.A.dylib        0x178d8 objc_exception_throw 2 CoreFoundation        0xf9c58 __CFDictionaryCreateGeneric 3 UIFoundation         0x220e0 -[NSTextContentStorage locationFromLocation:withOffset:] 4 UIFoundation         0x9f104 -[NSTextLineFragment textLineFragmentRange] 5 UIFoundation         0x86e70 __95-[NSTextLayoutManager _copyTextLineFragmentRangeForPoint:inContainerAtLocation:pointPlacement:]_block_invoke 6 CoreFoundation        0xa3a0 NSARRAY_IS_CALLING_OUT_TO_A_BLOCK 7 CoreFoundation        0x910e0 -[__NSArrayI  enumerateObjectsWithOptions:usingBlock:] 8 UIFoundation         0x86cfc -[NSTextLayoutManager _copyTextLineFragmentRangeForPoint:inContainerAtLocation:pointPlacement:] 9 UIFoundation         0x86eb4 -[NSTextLayoutManager lineFragmentRangeForPoint:inContainerAtLocation:] 10 UIFoundation         0x7e6ec -[NSTextSelectionNavigation _lineFragmentInfoForPoint:inContainerAtLocation:bounds:layoutOrientation:beforeLineFragment:afterLineFragment:lineFragmentRange:] 11 UIFoundation         0x815d8 -[NSTextSelectionNavigation textSelectionsInteractingAtPoint:inContainerAtLocation:anchors:modifiers:selecting:bounds:] 12 UIKitCore           0x98f5d8 -[_UITextKit2LayoutController cursorPositionAtPoint:inContainer:] 13 UIKitCore           0xf33d88 -[UITextInputController _characterPositionForPoint:] 14 UIKitCore           0xf4a2cc -[UITextView closestPositionToPoint:] 15 UIKitCore           0xedef5c -[UITextSelectionInteraction tappedToPositionCursorWithGesture:atPoint:granularity:completionHandler:] 16 UIKitCore           0xedecc8 -[UITextSelectionInteraction _checkForRepeatedTap:gestureLocationOut:] 17 UIKitCore           0xedf524 -[UITextSelectionInteraction _handleMultiTapGesture:] 18 UIKitCore           0x24ed54 -[UIApplication sendAction:to:from:forEvent:] 19 UIKitCore           0x9448fc -[UITextMultiTapRecognizer onStateUpdate:] 20 UIKitCore           0xbe874 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] 21 UIKitCore           0x42c9f0 _UIGestureRecognizerSendTargetActions 22 UIKitCore           0x1a60a4 _UIGestureRecognizerSendActions 23 UIKitCore           0x86a14 -[UIGestureRecognizer _updateGestureForActiveEvents] 24 UIKitCore           0x1328d8 _UIGestureEnvironmentUpdate 25 UIKitCore           0x9b7e14 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] 26 UIKitCore           0xf731c -[UIGestureEnvironment _updateForEvent:window:] 27 UIKitCore           0xfbc74 -[UIWindow sendEvent:] 28 UIKitCore           0xfaf44 -[UIApplication sendEvent:] 29 Aspen             0x6963c0 TimerApplication.sendEvent(_:) () 30 Aspen             0x696834 @objc TimerApplication.sendEvent(_:) () 31 UIKitCore           0xfa600 __dispatchPreprocessedEventFromEventQueue Also, the app was re-released in Appstore with Xcode 14.0. Any help would be appreciated.
Replies
1
Boosts
0
Views
1.3k
Activity
Nov ’22
UITextView crash iOS 16.2 beta1 & beta2
The code has been working for serval years. now it crashes when running on iOS 16.2 beta1 & beta2 UITextView *text = [[UITextView alloc] init]; text.attributedText = attributedText; text.frame = CGRectZero; text.editable = NO; text.scrollEnabled = NO; text.clipsToBounds = NO; text.showsVerticalScrollIndicator = NO; text.showsHorizontalScrollIndicator = NO; text.textContainer.lineFragmentPadding = 0; text.textContainerInset = UIEdgeInsetsZero; text.contentInset = UIEdgeInsetsZero; text.tag = index; [self addSubview:text]; crash log Last Exception Backtrace: 0 CoreFoundation 0x1b9849e88 __exceptionPreprocess + 164 1 libobjc.A.dylib 0x1b2b5b8d8 objc_exception_throw + 60 2 CoreFoundation 0x1b9939c58 __CFDictionaryCreateGeneric + 0 3 UIFoundation 0x1c3c937f4 -[NSCountableTextLocation compare:] + 204 4 UIFoundation 0x1c3d0d3fc -[NSTextRange textRangeByIntersectingWithTextRange:] + 144 iPhone OS 16.2 (20C5032e).crash the system is upgraded to iPhone OS 16.2 (20C5043e) from iPhone OS 16.2 (20C5032e) ,it also crash iPhone OS 16.2 (20C5043e).crash Guess it may be caused by the upgrade from TextKit1 to TextKit2. // 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)); then call layoutManager,'fall back' to TextKit 1, it work! can I ask the question,What is the cause of the problem? can it be fixed on the 16.2 beta3 or release version? Thank you very much!
Replies
1
Boosts
0
Views
1.6k
Activity
Nov ’22
The problem that specific character height and spacing 0 cannot be set using NSMutableAttributedString
We are adding a function to change the height and spacing of only certain characters (NewLine) using NSMutableAttributedString. Set font size to 0 and lineSpacing to 0. For characters other than specific characters, enter the font size and lineSpacing separately. (e.g. font size = 28.0 / lineSpacing = 16.0) When applied to UITextView , the space in that part is higher than the lineSpacing set for other lines. (In other words, I set the font size and linespace to 0 for a blank line, but the height occurs in the blank line.) I thought that by setting the font size and lineSpacing to 0, the line height would be 0. But it doesn't appear that way. Does anyone know of this issue? If there is something I don't understand, please let me know, it will help me to solve it. The iOS version is being developed in the 16.1 environment.
Replies
0
Boosts
0
Views
1.1k
Activity
Oct ’22
Has anyone solved the UITableView text persistence or overlapping issue in iOS 16.1 iPhone 14 Pro and 14 Pro Max?
Has anyone solved the UITableView text persistence or overlapping issue in iOS 16.1 iPhone 14 Pro and 14 Pro Max? If anyone has solved the problem by modifying the code, please reply. I posted on the forum a while ago and forwarded the issue to Apple Feedback. Link to the forum post: https://developer.apple.com/forums/thread/718401 (Sample code and video links are in the article above.) However, it was confirmed today that iOS 16.1 did not improve on the iPhone 14 Pro Max. After making the cell of UITableView display text with UITextView or UILabel The text color is set to black and the background to white. (The afterimage is displayed in black, so it must be reproduced with a white background.) UITableView srollToRow Calls the next or previous Row in the current Row without any animation effects as shown in the code below. tableView!.scrollToRow(at: IndexPath(row: self.pIndex, section: 0), at: .top, animated: false) And the call to scrollToRow is UITapGestureRecognizer , which makes it scroll one page at a time when the user taps. At this time, the cell height of UITableView is set to the total height of the device. This will briefly display the text content that was just previously displayed in black. (Sometimes it is displayed a little longer.) So the current page text and the previous page text overlap. There is a phenomenon that the contents of the previous page disappear. In a slightly animated effect, it feels like a transition to the next page, leaving an afterimage of the previous page content. But I didn't add any animation effects in the motion. This is definitely happening on the iPhone 14 Pro and 14 Pro Max. We think it might be an iOS error. I don't think it will be improved as iOS will be updated soon. (No feedback from Apple as of today.) So, if you have experienced the same problem and solved it through code, please help. Even if it is improved with an OS update in the future, there are users who are currently uncomfortable, so if there is a way, I am thinking of including it in the app update.
Replies
1
Boosts
0
Views
1.4k
Activity
Oct ’22
NSTextField not showing attributed string
I am trying to create a simple NSTextField where the entire text content should be a link. The text field is created/positioned in Interface Builder and later propagated with actual data by the view controller. However, the text field does not display my attributed string. In order to keep things neat and tidy, I subclassed NSTextField like so: public class MyLink: NSTextField {     private var linkRange: NSRange?     override init(frame frameRect: NSRect) {         super.init(frame: frameRect)     }     required init?(coder: NSCoder) {         super.init(coder: coder)     }     public func setLinkContent(text: String, to url: URL, range: NSRange?) {         allowsEditingTextAttributes = true         isSelectable = true         let attributedLink = NSMutableAttributedString(string: text)         self.linkRange = range ?? NSRange(location: 0, length: text.count)         attributedLink.addAttribute(.link, value: url, range: self.linkRange!)         attributedLink.addAttributes([             .foregroundColor: NSColor.red,             .underlineStyle: NSUnderlineStyle.single,             .cursor: NSCursor.pointingHand,             .font: NSFont.systemFont(ofSize: 16)         ], range: self.linkRange!)         self.attributedStringValue = attributedLink     } } To put things in perspective, the view controller calls setLinkContent to propagate the text field data. And after that - nothing (see image). You see that the text field is there because of the blue background color I set, but the actual text is not propagated. Configuration of the TextField in IB:
Replies
0
Boosts
1
Views
1.2k
Activity
Oct ’22
How do I get the value of UITextField text instance property and update UITableView row whenever the user edits the UITextField text property?
0 How would I update a table view row as as a text field text changes? It is difficult to create a string from the arguments in textField(:shouldChangeCharactersIn:replacementString:) so that the string I create would be equal to the string value of the text property of the text field after the textField(:shouldChangeCharactersIn:replacementString:) occurs. Is there a way to use the UITextInput protocol of UITextField? I haven't found anything on stackoverflow about using the UITextInput protocol of UITextField except a question in 2012 using Objective-C that asks why he's getting a crash.
Replies
3
Boosts
0
Views
1.5k
Activity
Oct ’22
Editable textview
Characters overlap on textview entry using buttons input
Replies
0
Boosts
0
Views
929
Activity
Sep ’22
TextKit2 Multi Column Layout
I'm trying to implement a multi column layout for a hex editor using TextKit2. I'm using the sample App named "LayoutTextWithTextKit2" as my starting point, but I'm struggling to understand what the best approach could be to implement it. My doubts are: Is it a good idea to use a text element for a single line in a single column? I'm basing my text element on NSTextParagraph. Following my previous question, is there any way to layout these text elements horizontally in a single line, instead of having the layout engine automatically lay them out in a vertical stack? Where is the correct location where I can override the positioning for each text element manually if I wanted to not base my elements in NSTextParagraph? Would this be a good idea? I apologize for the many questions, but my basic problem is that it's not clear to me if I'm missing something that's obvious, and there's a simple way to address my troubles. Any guidance towards that goal, even beyond my questions above, will be appreciated. I'm attaching an image showing two fragments that I'd like to be laid out horizontally in the same line, for reference.
Replies
0
Boosts
0
Views
1.2k
Activity
Sep ’22
UITextView iOS16 - access to layoutManager property of textview cause crash
The code has been working for serval years. now it crashes when running on iOS 16 and on the layoutManager = textView.layoutManager . It seems the TextKit 1 compatibility mode became active, but it still crashes on some of the textView if the first word is Arabic. static func didTapTerm(_ sender: UITapGestureRecognizer) -> String? {   guard let senderView = sender.view, (senderView is UITextView) else {     return nil   }   let textView = senderView as! UITextView,   layoutManager = textView.layoutManager       var location = sender.location(in: textView)   location.x -= textView.textContainerInset.left   location.y -= textView.textContainerInset.top       // find the value   // character index at tap location   let textContainer = textView.textContainer,   characterIndex = layoutManager.characterIndex(for: location, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil),   textStorage = textView.textStorage       guard characterIndex < textStorage.length else {     return nil   }       var range = NSRange()   if let phrase = textStorage.attribute(customAttributedStringKey,                    at: characterIndex,                    effectiveRange: &range) {     if let ph = phrase as? String {       // update UI ...     }     return phrase as? String   }   return nil } This is a console log: 2022-09-15 13:29:55.532693-0700 DictionaryApp[1101:95240] [Text] UITextView 0x1051cd600 is switching to TextKit 1 compatibility mode because its layoutManager was accessed. Break on void _UITextViewEnablingCompatibilityMode(UITextView *__strong, BOOL) to debug. 2022-09-15 13:29:55.543047-0700 DictionaryApp[1101:95240] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange invalid char range 1 2022-09-15 13:29:55.543166-0700 DictionaryApp[1101:95240] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange character count mismatch 2022-09-15 13:32:06.118905-0700 DictionaryApp[1101:95240] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range {5, 99} out of bounds; string length 103' *** First throw call stack: (0x1ab8f2248 0x1a4cbfa68 0x1a5d7c484 0x1b5b42260 0x1b5b5710c 0x1b5b55a14 0x1b5b73a20 0x1b5b73924 0x1b5b44df4 0x1b5b43cf4 0x1b5b639c0 0x1b5b61b08 0x1b5b61778 0x1b5b6125c 0x1ae9adcc4 0x1adaa76d0 0x1ae9ada3c 0x1adb8bfa0 0x1025ce384 0x102474d9c 0x102475154 0x1adb35164 0x1adea2dfc 0x1adc1cb94 0x1adafd1dc 0x1adba9358 0x1ae42a1d8 0x1adb6dd18 0x1adb72674 0x1adb71944 0x1adb71000 0x1adbb8d64 0x1adec14dc 0x1ab9be22c 0x1ab9ca614 0x1ab94e51c 0x1ab963eb8 0x1ab9691e4 0x1e4789368 0x1ade18d88 0x1ade189ec 0x102661fb0 0x1c9c8d948) libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSBigMutableString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range {5, 99} out of bounds; string length 103' terminating with uncaught exception of type NSException This is the backtrace:
Replies
0
Boosts
4
Views
2.1k
Activity
Sep ’22
NSTextView ignore specific char input
I have a NSTextView, and I want to forbid users from typing in some specific character like "K", (when "K" is pressed,ignore the input, and don't change the underlying textStorage). is there a way I can do it? appreciate very much
Replies
1
Boosts
0
Views
1k
Activity
Aug ’22
Is MacCatalyst UITextview's Spellchecker broken?
UITextview's Spellchecker seem not to detect spells and show red dots at odd position in MacCatalyst: It does work well in iPhone and iPad though. I've activated the Spellcheck through storyboard, also tested with both Normal and Attributed strings. Even tried disabling the scrolling. But nothing seems to help! Does any one know about this behaviour?
Replies
1
Boosts
1
Views
1.3k
Activity
Jul ’22
How to achieve NSSharingService menu options for NSTextAttachments inside UITextView in MacCatalyst?
When I hover the mouse over the NSTextAttachment image inside the UITextview, it should show this option to MarkUp. All native app including Notes, TextEditor, Mail have this behaviour: I think, by default, NSTextView will show the NSSharingServicePicker button when you hover over an image inside the text view. That’s true even for custom image-based NSTextAttachments in the attributed string. But it is not showing the button for UITextview in MacCatalyst. Also NSSharingService class is limited to MacOS only. Are there any alternative way to achieve this in MacCatalyst?
Replies
0
Boosts
0
Views
1.2k
Activity
Jul ’22
UITextView + TextKit 2: Are we allowed to configure our own custom rendering surface when using UITextView?
Hi TextKit 2 Team, I'm trying to configure my own custom rendering surface when using UITextView(usingTextLayoutManager: true). What I'm currently doing is adding a "contentLayer: CALayer" into my UITextView and adding my rendering surfaces into that. The issue I'm running into, is that the rendering surface will display the first character I input, but then will not update for subsequent text until: It becomes long enough to cause a line wrap. I hit return. Not sure if I'm doing something wrong? So my questions are: Is using configureRenderingSurface API intended to be used when I'm using UITextView? Or it's only meant for when I do fully custom InputView? Should I be inserting my rendering surfaces into my contentLayer or is there some more appropriate place for me to insert into? How do I properly trigger redraw or invalidation of my rendering surface on text editing changes? Is this a bug or do I have to trigger an update manually somewhere? Many thanks in advance!
Replies
0
Boosts
0
Views
1.4k
Activity
Jun ’22
How to access the textContentStorage of UITextView in iOS 16?
Hi TextKit team, How do I access the textContentStorage of UITextView that is usingTextLayoutManager: true? I'd like to use the NSTextContentStorageDelegate methods, but unlike NSTextView where it has a property for textContentStorage, it seems UITextView doesn't expose this? Thanks for your help in advance! Cheers / Leo
Replies
1
Boosts
0
Views
1.3k
Activity
Jun ’22
Where is the TextKitAndTextView sample code?
Hi TextKit2 Team, I'm trying to find the link to download the TextKitAndTextView sample code that was mentioned in the "What's new in TextKit and text views" video. I can't seem to find a link to it anywhere though. Cheers / Leo
Replies
1
Boosts
0
Views
1.2k
Activity
Jun ’22
Discover Fonts with MATH Table Automatically?
Is there a simple way to create an NSFontCollection based on NSFontDescriptor querying to gather all installed/available fonts with a MATH table? It doesn't look like there's an attribute for that, but I don't know how else to search other than correlating with features like ssty, dtls, and flac.
Replies
0
Boosts
0
Views
974
Activity
Jun ’22
Is TextKit 2 built on Core Text?
It's a simple question. I'm just trying to understand how these things fit together. Core Text doesn't seem to get updated much, but maybe that's because it's low level and doesn't need it. I assume it's still the recommended way to do low-level text things not handled by TextKit. ?
Replies
1
Boosts
0
Views
1.6k
Activity
Jun ’22