简体   繁体   English

是否可以从中检索用于生成CTLine变量的原始字符串?

[英]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. 我想测试Core Text CTLineRef变量内的tap事件。 I have a CTLineRef variable, touchedLine , that I have retrieved by iterating over the CTLine s in a frame. 我有一个CTLineRef变量touchedLine ,可以通过遍历框架中的CTLine获取。 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 . 一旦找到在命中范围内的字符串, 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? 现在假设在不重构一部分代码的情况下不容易访问用于创建此字符串数据的字符串数据,我touchedLinetouchedLine本身(某种CTLineGetAttributedString函数)中检索用于创建CTLineRef变量touchedLine的原始NSAttributedString

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. 由于它是不透明的类型,因此CTLine应该包含数据,但是除了Apple文档中列出的功能之外,似乎没有其他方法可以检索它们。 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...) (需要记住的一个警告,这帮助我解决了最初的问题,是您正在使用CTLineGetStringIndexForPosition定位的坐标系相对于系统的其余部分y翻转-整个Core Text问题再次...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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