[英]PDFTron change arrow annotation direction iOS
The default PTArrowCreate
class draws arrows pointing to the user's initial tap on the screen.默认的
PTArrowCreate
class 绘制指向用户在屏幕上的初始点击的箭头。 I want arrows to be pointing at the place where user did finish dragging finger.我希望箭头指向用户完成拖动手指的地方。
Please give me a clue how can i achieve this.请给我一个线索,我怎样才能做到这一点。
There isn't currently a built-in option for this, but you can implement this via subclassing.目前没有内置选项,但您可以通过子类化来实现。 Arrow annotations are created using the tool
PTAnnotCreate
, which you can subclass by registering a subclass before the PTDocumentViewController
is created:箭头注释是使用
PTAnnotCreate
工具创建的,您可以在创建PTDocumentViewController
之前通过注册子类来创建子类:
[PTOverrides overrideClass:[PTArrowCreate class] withClass:[FWArrowCreate class]];
Then swap the head with the tail of the arrow in the subclass as follows:然后在子类中将头部与箭头的尾部交换如下:
@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
The same answer in Swift: 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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.