【发布时间】:2019-10-14 11:04:00
【问题描述】:
默认的PTArrowCreate 类绘制指向用户在屏幕上的初始点击的箭头。我希望箭头指向用户完成拖动手指的地方。
请告诉我如何实现这一点。
【问题讨论】:
默认的PTArrowCreate 类绘制指向用户在屏幕上的初始点击的箭头。我希望箭头指向用户完成拖动手指的地方。
请告诉我如何实现这一点。
【问题讨论】:
目前没有内置选项,但您可以通过子类化来实现。箭头注释是使用工具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
}
}
【讨论】: