且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

显示PDF内容时的UIWebView上下文菜单

更新时间:2023-11-30 22:16:04

使用巧妙的技巧,您可以覆盖基础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®.