Ios PDFKit高亮显示注释:四边形点

Ios PDFKit高亮显示注释:四边形点,ios,objective-c,swift,pdf,pdfkit,Ios,Objective C,Swift,Pdf,Pdfkit,我想使用PDFKit将突出显示注释添加到pdf文件中。我使用下面的代码来添加它 PDFPage* page = [self.pdfView.document pageAtIndex:0]; PDFAnnotation* annotation = [[PDFAnnotation alloc] initWithBounds:CGRectMake(206, 600, 60, 59) forType:PDFAnnotationSubtypeHighlight withProperties:nil]; a

我想使用PDFKit将突出显示注释添加到pdf文件中。我使用下面的代码来添加它

PDFPage* page = [self.pdfView.document pageAtIndex:0];
PDFAnnotation* annotation = [[PDFAnnotation alloc] initWithBounds:CGRectMake(206, 600, 60, 59) forType:PDFAnnotationSubtypeHighlight withProperties:nil];
annotation.color = UIColor.blueColor;
[page addAnnotation:annotation];
但它只高亮显示一个矩形,我想高亮显示多行文本。我找到了一个问题/答案

但这不是我想要的,它将添加许多高亮注释,我只想添加一个注释。我了解到关键值QuadPoints可以做到这一点。但是当我添加下面的代码时,它不起作用,甚至不能呈现注释

NSArray<NSValue *> *quadrilateralPoints = [[NSArray alloc] initWithObjects:
                                           [NSValue valueWithCGPoint:CGPointMake(206.0f, 659.0f)],
                                           [NSValue valueWithCGPoint:CGPointMake(266.0f, 659.0f)],
                                           [NSValue valueWithCGPoint:CGPointMake(206.0f, 600.0f)],
                                           [NSValue valueWithCGPoint:CGPointMake(266.0f, 600.0f)],
                                           nil];

annotation.quadrilateralPoints = quadrilateralPoints;
NSArray*四边形点=[[NSArray alloc]initWithObjects:
[NSValue VALUE WITH CGPOINT:CGPointMake(206.0华氏度,659.0华氏度)],
[NSValue VALUE WITH CGPOINT:CGPointMake(266.0华氏度,659.0华氏度)],
[NSValue VALUE WITH CGPOINT:CGPointMake(206.0华氏度,600.0华氏度)],
[NSValue VALUE WITH CGPOINT:CGPointMake(266.0华氏度,600.0华氏度)],
零];
注释.四边形点=四边形点;
那么现在我想知道如何实现它?或者如何使用四边形点?

我找到了答案: 下面的代码有效

NSArray<NSValue *> *quadrilateralPoints = [[NSArray alloc] initWithObjects:
                                       [NSValue valueWithCGPoint:CGPointMake(206.0 - 206, 659.0 - 600)],
                                       [NSValue valueWithCGPoint:CGPointMake(266.0 - 206, 659.0 - 600)],
                                       [NSValue valueWithCGPoint:CGPointMake(206.0 - 206, 600.0 - 600)],
                                       [NSValue valueWithCGPoint:CGPointMake(266.0 - 206, 600.0 - 600)],
                                       nil];

annotation.quadrilateralPoints = quadrilateralPoints;
NSArray*四边形点=[[NSArray alloc]initWithObjects:
[NSValue VALUE WITH CGPOINT:CGPointMake(206.0-206659.0-600)],
[NSValue VALUE WITH CGPOINT:CGPointMake(266.0-206659.0-600)],
[NSValue valueWithCGPoint:CGPointMake(206.0-206600.0-600)],
[NSValue VALUE WITH CGPOINT:CGPointMake(266.0-206600.0-600)],
零];
注释.四边形点=四边形点;

因为它基于原点边界,所以我发现更好的方法是使用.quadPoints注释键。此方法与PDF规范相匹配,不属于PDFAnnotationUtilities.h文件的一部分,该文件是为兼容旧函数而提供的。这种方式不需要调整边界

let quadPoints:[CGPoint] = [CGPoint(x:206.0, y:659.0),
                            CGPoint(x:266.0, y:659.0),
                            CGPoint(x:206.0, y:600.0),
                            CGPoint(x:266.0, y:600.0)]


annotation.setValue(quadPoints, forAnnotationKey: .quadPoints)

要完成回答,还应使用PDFSelection的selectionsByLine功能获取特定页面上的所有选择,并按照中的说明每页进行一次注释