[英]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? 现在假设在不重构一部分代码的情况下不容易访问用于创建此字符串数据的字符串数据,我
touchedLine
从touchedLine
本身(某种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.