【问题标题】:PDFTron change arrow annotation direction iOSPDFTron 更改箭头注释方向 iOS
【发布时间】:2019-10-14 11:04:00
【问题描述】:

默认的PTArrowCreate 类绘制指向用户在屏幕上的初始点击的箭头。我希望箭头指向用户完成拖动手指的地方。

请告诉我如何实现这一点。

【问题讨论】:

    标签: ios swift pdftron


    【解决方案1】:

    目前没有内置选项,但您可以通过子类化来实现。箭头注释是使用工具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
    

    【讨论】:

    • 遗憾的是,PTArrowCreate 工具中没有自定义点。 @James 也许你也知道改变箭头杯样式的方法?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多