本页内容
调整已存在的测量注释
对于已经存在的测量注释,改变测量的点值时(如CPDFPolylineAnnotation
的 savePoints
),需要刷新测量属性,从而得到新的的测量值。
**注意:**无法通过将测量注释的测量属性设置为空来消除测量属性
以下是修改已存在折线距离测量注释的示例代码:
swift
// 获取需要创建便签的页面对象
if let page = document?.page(at: 0) {
// 创建折线注释
var anotation = CPDFPolylineAnnotation(document: document)
// 设置折线的的顶点
var pointsArray: [NSValue] = []
let point1 = CGPoint(x: 100, y: 100)
pointsArray.append(NSValue(cgPoint: point1))
let point2 = CGPoint(x: 100, y: 200)
pointsArray.append(NSValue(cgPoint: point2))
let point3 = CGPoint(x: 200, y: 200)
pointsArray.append(NSValue(cgPoint: point3))
anotation?.setSavePoints(pointsArray)
// 设置测量属性
var measureInfo = CPDFPerimeterMeasureInfo()
//设置MeasureInfo:相关信息需要在将其加在页面后才会有效
anotation.measureInfo = measureInfo;
// 更新注释外观使其显示在文档上
page.addAnnotation(anotation!)
// 新增折线的顶点数
let point4 = CGPoint(x: 200, y: 300)
pointsArray.append(NSValue(cgPoint: point4))
anotation?.setSavePoints(pointsArray)
// 刷新测量属性,重新计算
anotation.measureInfo = measureInfo;
// 刷新注释外观
anotation.updateAppearanceStream()
}
objective-c
// 获取需要创建便签的页面对象
CPDFPage *page = [document pageAtIndex:0];
// 创建折线注释
CPDFPolylineAnnotation *anotation = [[CPDFPolylineAnnotation alloc] initWithDocument:document];
// 设置折线的的顶点
NSMutableArray<NSValue *> *pointsArray = [NSMutableArray array];
CGPoint point1 = CGPointMake(100, 100);
[pointsArray addObject:[NSValue valueWithCGPoint:point1]];
CGPoint point2 = CGPointMake(100, 200);
[pointsArray addObject:[NSValue valueWithCGPoint:point2]];
CGPoint point3 = CGPointMake(200, 200);
[pointsArray addObject:[NSValue valueWithCGPoint:point3]];
[anotation setSavePoints:savePoints];
// 设置测量属性
CPDFPerimeterMeasureInfo *measureInfo = [[CPDFPerimeterMeasureInfo alloc] init];
[anotation setMeasureInfo:measureInfo];
// 更新注释外观使其显示在文档上
[page addAnnotation:anotation];
// 新增折线的顶点数
CGPoint point4 = CGPointMake(200, 300);
[pointsArray addObject:[NSValue valueWithCGPoint:point4]];
[anotation setSavePoints:savePoints];
// 刷新测量属性,重新计算
//设置MeasureInfo:相关信息需要在将其加在页面后才会有效
anotation.measureInfo = measureInfo;
// 刷新注释外观
[anotation updateAppearanceStream];