简体   繁体   中英

Can the original string used to generate a CTLine variable be retrieved from it?

I want to test for a tap event within a Core Text CTLineRef variable. I have a CTLineRef variable, touchedLine , that I have retrieved by iterating over the CTLine s in a frame. Once I have found the string with a hit within its bounds, I retrieve the index of the character in the original string from CTLineGetStringIndexForPosition .

Supposing now that the string data used to create this is not readily accessible without restructuring a portion of the code, can I retrieve the original NSAttributedString used to create the CTLineRef variable touchedLine from touchedLine itself---some sort of a CTLineGetAttributedString function?

Since it is an opaque type, CTLine should contain the data, but there appears to be no way to retrieve them beyond the listed functions in the Apple documentation. So, briefly, no, there isn't .

(One caveat to keep in mind, which helped me solve my initial problem, is that the coordinate system which you are using for the position with CTLineGetStringIndexForPosition may be y-flipped relative to the rest of your system---that whole Core Text thing again...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM