首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何阻止PDFNet操作的执行?

如何阻止PDFNet操作的执行?
EN

Stack Overflow用户
提问于 2014-08-25 14:31:45
回答 1查看 247关注 0票数 1

基本上,我正在尝试截取指向远程文件的链接,而不是打开我已经存储的本地版本。

在链接被点击后,我能够进入它的操作,但是我想不出如何在保持URL完整的情况下阻止它执行默认行为。

以下是相关代码:

代码语言:javascript
复制
- (void)pdfScrollViewTap:(UITapGestureRecognizer *)gestureRecognizer
{

Annot *annotation;

@try {
    // If they are clicking an annotation, we don't want to process this
    [self.pdfView DocLockRead];
    CGPoint down = [gestureRecognizer locationInView:self.pdfView];
    annotation = [self.pdfView GetAnnotationAt:down.x y:down.y];
}
@catch (NSException *exception) {
    // something is wrong with the annotation, it may not be selected properly
}
@finally {
    [self.pdfView DocUnlockRead];
}

// This is how we find out a Link was tapped
if ([annotation IsValid]) {
    if (annotation.GetType == e_Link) { // Its a link
        Link *link = [[Link alloc] initWithAnn:annotation]; // here's the link
        Action *action = link.GetAction; // links have an action, heres that
        if ([action IsValid]) { // hopefully its valid
            if (action.GetType == e_URI) { // URI is the URL the link points to
                if ([self.delegate respondsToSelector:@selector(shouldOpenURLforLinkAnnotation:withViewController:)]) { // Check if the delegate implements this
                    NSString *origURL = [action.GetSDFObj FindObj:@"URI"].GetAsPDFText;
                    if (![self.delegate shouldOpenURLforLinkAnnotation:origURL withViewController:self]) {
                        // The delegate handles finding and opening the local file

                        // Find a away to disable or stop the action here

                    }
                }
            }
        }
    }
    return;
}
}

我试过简单地删除以下操作:

代码语言:javascript
复制
[link RemoveAction];

这是第一次工作,但正如预期的那样,该操作在删除后再也不会被调用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-26 18:16:14

链接操作由工具代码执行,它实现了所有的用户交互功能,如文本选择、表单填充、注释创建/编辑和链接跟踪。要定制链接处理行为,您应该在/Lib/src/PDFViewCtrlTools/Tools /Tools中修改AnnotEditTool.m的源代码,并编译libTools.a的新副本。

代码语言:javascript
复制
else if( actionType == e_URI )
{
    Obj* sdfObj = [action GetSDFObj];
    Obj* uriObj = [sdfObj FindObj:@"URI"];

    if( uriObj != Nil )
    {
        NSString* uriDestination = [uriObj GetAsPDFText];

        // appends http if no scheme is present
        uriDestination = [Link GetNormalizedUrl:uriDestination];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString: uriDestination]];
        });




        return YES;
    }
}

你会想要做一些openURL:以外的事情

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25488257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档