显示PDF内容时的UIWebView上下文菜单 [英] UIWebView contextual menu while displaying PDF content

查看:66
本文介绍了显示PDF内容时的UIWebView上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用UIWebView来显示不同类型的文件,例如html,pdf,doc等.

In my application, I use UIWebView to display different types of files like, html, pdf, doc etc.

我正在通过禁用标注和使用手势识别器来自定义html内容的上下文菜单.它适用于html内容.

I am customizing the contextual menu on html content, by disabling callout and using gesture recognizer. It works fine for html content.

但是,当显示pdf内容时,Web视图使用与corepdf框架(专用框架)不同的类.因此,处理html内容的技术都无法与pdf内容一起使用.

However when displaying pdf content web view uses different classes from corepdf framework which is private framework. So none of the technique which worked on html content works with pdf content.

UIWebView使用UIPDFPageView和相关类在长按超链接时显示上下文菜单.

UIWebView uses UIPDFPageView and related classes to display contextual menu on long pressing on hyperlink.

是否有任何方法可以覆盖上下文菜单的显示而无需处理私有框架?

Is there any method to override the display of contextual menu without having to deal with private framework?

推荐答案

使用巧妙的技巧,您可以覆盖基础UIWebDocumentView-canPerformAction:withSender:方法,以仅传递您希望显示的内容.这也适用于PDF,因为内部类在视图层次结构中更深,并且使用UIWebDocumentView应该没问题.

With clever tricks, you can override the underlying UIWebDocumentView's -canPerformAction:withSender: method to only pass what you wish to display. This should work for PDF as well, as the internal classes are deeper in the view hierarchy and you should be fine with the UIWebDocumentView.

在iOS5、6和7种子1上,UIWebDocumentView对象是UIWebView滚动视图的子视图.我要做的是找到滚动视图的子视图,该子视图的类名中带有@"UIWeb"前缀,并使用Objective C运行时将其动态子类化为我自己的子类(我在运行时创建它,就像系统为它所做的那样)键值观察)并用我自己的实现替换.您甚至可以通过调用super来调用先前的实现.

On iOS5, 6 and 7 seed 1, the UIWebDocumentView object is a subview of the scroll view of the UIWebView. What I do is find the subview of the scroll view that has the @"UIWeb" prefix in its class name, and use the Objective C runtime to dynamically subclass it to my own subclass (I create it at runtime - like what the system does for key-value observing) and replace the implementation with my own. You can even call the previous implementation by calling the super.

这很骇人,但似乎很安全.苹果似乎没有引入离线的UIWebView(使用XPC),因此它在iOS7上也应该是安全的.

This is hacky, but it seems to be safe. Apple does not seem to have introduced the off-process UIWebView (using XPC), so it should be safe with iOS7 as well.

一如既往的免责声明,this API is not documented and is subject to change at any given moment, and your app may stop functioning at any time®.

As always the disclaimer, this API is not documented and is subject to change at any given moment, and your app may stop functioning at any time®.

这篇关于显示PDF内容时的UIWebView上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆