PDFTron 更改箭头注释方向 iOS
PDFTron change arrow annotation direction iOS
默认 PTArrowCreate
class 绘制指向用户在屏幕上的初始点击的箭头。我希望箭头指向用户完成拖动手指的地方。
请给我一个线索,我怎样才能做到这一点。
目前没有内置选项,但您可以通过子类化来实现。箭头注释是使用工具 PTAnnotCreate
创建的,您可以在创建 PTDocumentViewController
之前通过注册子类来对其进行子类化:
[PTOverrides overrideClass:[PTArrowCreate class] withClass:[FWArrowCreate class]];
然后在子类中将箭头的头尾互换如下:
@interface FWArrowCreate : PTArrowCreate
@end
@implementation FWArrowCreate
-(void)swapStartAndEndPoints
{
CGPoint savedStartPoint = self.startPoint;
self.startPoint = self.endPoint;
self.endPoint = savedStartPoint;
}
-(void)drawRect:(CGRect)rect
{
[self swapStartAndEndPoints];
[super drawRect:rect];
[self swapStartAndEndPoints];
}
- (BOOL)pdfViewCtrl:(PTPDFViewCtrl*)pdfViewCtrl onTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self swapStartAndEndPoints];
BOOL result = [super pdfViewCtrl:pdfViewCtrl onTouchesEnded:touches withEvent:event];
[self swapStartAndEndPoints];
return result;
}
@end
Swift中的相同答案:
class MyArrowCreate: PTArrowCreate {
override func draw(_ rect: CGRect) {
swapPoints()
super.draw(rect)
swapPoints()
}
override func pdfViewCtrl(_ pdfViewCtrl: PTPDFViewCtrl, onTouchesEnded touches: Set<UITouch>, with event: UIEvent?) -> Bool {
swapPoints()
let result = super.pdfViewCtrl(pdfViewCtrl, onTouchesEnded: touches, with: event)
swapPoints()
return result
}
private func swapPoints() {
let tmpPoint = startPoint
startPoint = endPoint
endPoint = tmpPoint
}
}
默认 PTArrowCreate
class 绘制指向用户在屏幕上的初始点击的箭头。我希望箭头指向用户完成拖动手指的地方。
请给我一个线索,我怎样才能做到这一点。
目前没有内置选项,但您可以通过子类化来实现。箭头注释是使用工具 PTAnnotCreate
创建的,您可以在创建 PTDocumentViewController
之前通过注册子类来对其进行子类化:
[PTOverrides overrideClass:[PTArrowCreate class] withClass:[FWArrowCreate class]];
然后在子类中将箭头的头尾互换如下:
@interface FWArrowCreate : PTArrowCreate
@end
@implementation FWArrowCreate
-(void)swapStartAndEndPoints
{
CGPoint savedStartPoint = self.startPoint;
self.startPoint = self.endPoint;
self.endPoint = savedStartPoint;
}
-(void)drawRect:(CGRect)rect
{
[self swapStartAndEndPoints];
[super drawRect:rect];
[self swapStartAndEndPoints];
}
- (BOOL)pdfViewCtrl:(PTPDFViewCtrl*)pdfViewCtrl onTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self swapStartAndEndPoints];
BOOL result = [super pdfViewCtrl:pdfViewCtrl onTouchesEnded:touches withEvent:event];
[self swapStartAndEndPoints];
return result;
}
@end
Swift中的相同答案:
class MyArrowCreate: PTArrowCreate {
override func draw(_ rect: CGRect) {
swapPoints()
super.draw(rect)
swapPoints()
}
override func pdfViewCtrl(_ pdfViewCtrl: PTPDFViewCtrl, onTouchesEnded touches: Set<UITouch>, with event: UIEvent?) -> Bool {
swapPoints()
let result = super.pdfViewCtrl(pdfViewCtrl, onTouchesEnded: touches, with: event)
swapPoints()
return result
}
private func swapPoints() {
let tmpPoint = startPoint
startPoint = endPoint
endPoint = tmpPoint
}
}