我已经编写了在拖动鼠标时移动注释的代码,但结果显示注释移动到鼠标移动轨迹的相反方向。它以鼠标第一次点击中心移动,中心对称相反...我为注释绑定绘制了一个Rect,但是Rect位置是正确的......
有两张图片显示发生的事情:
- 在我拖动之前:
注释消失了......
以下是我的代码:
- (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类....