默认的PTArrowCreate
类在屏幕上绘制指向用户最初点击的箭头。我希望箭头指向用户确实拖动手指的位置。
请给我一个提示,我如何实现这一目标。
答案 0 :(得分:2)
当前没有内置选项,但是您可以通过子类实现。箭头注释是使用工具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
答案 1 :(得分:0)
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
}
}