2

我已经编写了在拖动鼠标时移动注释的代码,但是结果显示注释移动到了与鼠标移动轨迹相反的方向。它以鼠标第一次单击点为中心移动,中心对称相反...我为注释的边界绘制了一个矩形,但矩形位置是正确的...

有两张图片告诉你发生了什么:

- 在我拖动之前:

在我拖动之前:

  • 我搬家后:

在此处输入图像描述

注释消失了....

下面是我的代码:

- (void) mouseDragged: (NSEvent *) theEvent
{


                    // Move annotation.
                    // Hit test, is mouse still within page bounds?
                    if (NSPointInRect([self convertPoint: mouseLoc toPage: activePage],
                                      [[_activeAnnotation page] boundsForBox: [self displayBox]]))
                    {
                        // Calculate new bounds for annotation.
                        newBounds = currentBounds;
                        newBounds.origin.x = roundf(endPt.x - _clickDelta.x);
                        newBounds.origin.y = roundf(endPt.y - _clickDelta.y);
                    }
                    else
                    {
                        // Snap back to initial location.

                        newBounds = _wasBounds;
                    }
// Change annotation's location.
            [_activeAnnotation setBounds: newBounds];

            // Call our method to handle updating annotation geometry.
            [self annotationChanged];

            // Force redraw.
            dirtyRect = NSUnionRect(currentBounds, newBounds);
            dirtyRect.origin.x -= 10;
            dirtyRect.origin.y -= 10;
            dirtyRect.size.width += 20;
            dirtyRect.size.height += 20;
              [super setNeedsDisplay:YES];
            [self setNeedsDisplayInRect:RectPlusScale([self convertRect: dirtyRect fromPage: [_activeAnnotation page]], [self scaleFactor])];

 [super mouseDragged: theEvent];

奇怪的是,如果注释是图像或文本,则移动是正确的。它只发生在 PDFAnnotationInk 类中......

4

0 回答 0