UIWebView without Copy/Paste when displaying PDF files

前端 未结 8 971
醉话见心
醉话见心 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:48

    Here is a modification to Zubaba's answer in Swift 3 that ended up working for me to eliminate warning. I changed assignment longPress.delegate = self to longPress.delegate = self as? UIGestureRecognizerDelegate.

        let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress))
        longPress.allowableMovement = 100
        longPress.minimumPressDuration = 0.3
        longPress.delegate = self as? UIGestureRecognizerDelegate
        longPress.delaysTouchesBegan = true
        longPress.delaysTouchesEnded = true
        longPress.cancelsTouchesInView = true
        webView.addGestureRecognizer(longPress)
        webView.scrollView.addGestureRecognizer(longPress)
    
        webView.loadRequest(request)
    

提交回复
热议问题