PDFViewAnnotationHitNotification未送达

时间:2012-09-17 18:06:37

标签: macos appkit pdfkit

我正在Mac上实现PDF查看器,我想让用户添加注释。

我已经在页面中添加了一个PDFAnnotationText,看起来很不错,但是当用户点击它时,整个文档会缩小,并且左侧会出现一个注释列表。

我想自定义此选项以将注释显示为弹出窗口,类似于预览。 PDFAnnotationText类引用说我可以这样做:

  

每个PDFAnnotationText对象都有一个与之关联的PDFAnnotationPopup对象。在关闭状态下,注释显示为图标。在打开状态下,它显示为包含注释文本的弹出窗口。请注意,您的应用程序必须执行工作以放置包含文本的窗口以响应PDFViewAnnotationHitNotification。

但是当我为PDFViewAnnotationHitNotification添加观察者时,单击注释时不会发送通知。

1 个答案:

答案 0 :(得分:0)

我已经联系过Apple,我收到的回答是这是一个错误。解决方法是自己处理鼠标单击,遍历注释并查找命中。

像这样的东西(在PDFView子类中的mouseDown处理程序中运行的代码):

NSPoint windowPoint = [self.window convertScreenToBase:[NSEvent mouseLocation]];
NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil];
PDFPage *page = [self pageForPoint:viewPoint nearest:NO];

if (page != nil) {
    NSPoint pointOnPage = [self convertPoint:viewPoint toPage:page];

    for (PDFAnnotation *annotation in page.annotations) {
        NSRect      annotationBounds;

        // Hit test annotation.
        annotationBounds = [annotation bounds];
        if (NSPointInRect(pointOnPage, annotationBounds))
        {
            NSLog(@"Annotation hit: %@", annotation);
        }
    }
}
相关问题