1

我试图CTFrameGetLineOrigins从这里弄清楚:CTFrameGetLineOrigins Got Incorrect Origins,并试图将 ObjC 转换为 Swift。

对象-C:

CFArrayRef lines = CTFrameGetLines(frame);
size_t numOfLines = CFArrayGetCount(lines);
CGPoint lineOrigins[numOfLines];
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins);

迅速:

let lines = CTFrameGetLines(frame)
let numOfLines: size_t = CFArrayGetCount(lines)
let lineOrigins = [CGPoint](repeating: CGPoint.zero, count: numOfLines)
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins)

但是我收到 CTFrameGetLineOrigins 的第三个参数的错误:
无法将类型“[CGPoint]”的值转换为预期的参数类型“UnsafeMutablePointer”

我如何克服这个错误?

4

2 回答 2

2

实际上我只是添加&了参数并使常量成为变量。

let lines = CTFrameGetLines(frame)
let numOfLines: size_t = CFArrayGetCount(lines)
var lineOrigins = [CGPoint](repeating: CGPoint.zero, count: numOfLines)
CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), &lineOrigins)
于 2018-09-13T19:06:56.053 回答
1

你可以试试

CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), UnsafeMutablePointer(&lineOrigins))

或直接

CTFrameGetLineOrigins(frame, CFRangeMake(0, 0),&lineOrigins)
于 2018-09-13T19:05:56.347 回答