简体   繁体   中英

PDFTron change arrow annotation direction iOS

The default PTArrowCreate class draws arrows pointing to the user's initial tap on the screen. 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:

[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:

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
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM