Using iOS 11, Swift 4, Xcode 9
Question upfront: Is there a way (or workaround) to force the layoutManager to obey the new orphaned text rule?
I am implementing a system for detecting which character a user taps within a label as in this answer: https://stackoverflow.com/a/42240972/7515904
I am printing the character index on each tap to compare to where I actually tapped. For cells 1-3 (image below), it prints exactly the correct index.
Cell 4 is affected by Apple's new (iOS11) orphaned text implementation:
- The word "septum" should be on line 1, but it is dropped to line 2 so that the word "infarction" isn't alone.
- The printed character index acts like "septum" is on line 1 (i.e. tapping white space to the right of "or" gives a higher index, and tapping text in the area of "infarction" does not.)
The functional line of code to detect character index is:
let indexOfCharacter = layoutManager.characterIndex(for: locationOfTouchInTextContainer, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
My assumption is that somehow the layoutManager doesn't use this orphaned text method, despite the fact that I made the attributedText within this layoutManager the same as the actual cell label.
Question: Is there a way (or workaround) to force the layoutManager to obey this new orphaned text rule? Thanks for any guidance!
NOTE: Ignore the blue underlined text - I am trying to get the function working before the visual representation.