所有x坐标都是正确的,但所有y坐标都不正确 - 总是3.40282e+38。如何为每个CTLine获得正确的y?
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)self.attString);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectMake(0, 0, self.frameSize.width, CGFLOAT_MAX));
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, self.attString.length), path, NULL);
CFArrayRef lines = CTFrameGetLines(frame);
size_t numOfLines = CFArrayGetCount(lines);
CGPoint lineOrigins[numOfLines];
CTFrameGetLineOrigins(frame, CFRangeMake(0, numOfLines), lineOrigins);
NSLog(@"Lines count %ld", numOfLines);
for (CFIndex i = 0; i < numOfLines; i++)
{
CTLineRef line = CFArrayGetValueAtIndex(lines, i);
[self draw:frame line:line];
NSLog(@"%@", NSStringFromCGPoint(lineOrigins[i]));
}
输出:
2014-04-11 10:45:27.095 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.099 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.105 Backgammon HD Narde[2221:707] {84.997, 3.40282e+38}
2014-04-11 10:45:27.111 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.117 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.121 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.124 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.126 Backgammon HD Narde[2221:707] {0, 3.40282e+38}
2014-04-11 10:45:27.128 Backgammon HD Narde[2221:707] {136.804, 3.40282e+38}
2014-04-11 10:45:27.132 Backgammon HD Narde[2221:707] {0, 3.40282e+38}