UIWebView without Copy/Paste when displaying PDF files

前端 未结 8 962
醉话见心
醉话见心 2020-12-10 20:21

I have tried to disable Copy/Paste in UIWebView by using a category and overriding canPerformAction and returning NO for copy, cut and paste selectors.

It worked

8条回答
  •  时光取名叫无心
    2020-12-10 20:38

    The UILongPressGestureRecognizer is located in the UIPDFPageView. To get access to this view look at the view hierarchy in the Debug menu, currently you can access this view like so once you load the pdf to the web view:

    let pdfPageView = myWebView.scrollview?.subviews[0]?.subviews[0]
    

    Then to remove the Long Press use this method while passing in the pdfPageView:

    func removeLongPressFromView(view: UIView){
      if let gestures = view.gestureRecognizers{
        for gesture in gestures{
          if gesture is UILongPressGestureRecognzier{
            view.removeGestureRecognizer(gesture)
          }
        }
      }
    }
    

提交回复
热议问题