{"id":1596,"date":"2013-02-11T18:00:49","date_gmt":"2013-02-12T02:00:49","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1596"},"modified":"2013-02-11T18:01:08","modified_gmt":"2013-02-12T02:01:08","slug":"disable-copy-in-uiwebview","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1596","title":{"rendered":"Disable copy in UIWebView"},"content":{"rendered":"<p>Great answer from Zubaba at <a href=\"http:\/\/stackoverflow.com\/questions\/12768194\/uiwebview-without-copy-paste-when-displaying-pdf-files\">Stackoverflow<\/a>. I\u2019m using a webView to display colored and bolded text and I had the same problem. I put his solution into a method and call it just after I initialize the webView. I don\u2019t seem to need the delegate.<\/p>\n<p><pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\n\/\/ This is the end of the method where I initialize the web view\n&nbsp;&nbsp;&nbsp;&nbsp;self.textView = [[UIWebView alloc] initWithFrame:textFrame];\n&nbsp;&nbsp;&nbsp;&nbsp;[self longPress:self.textView];\n\n\/\/ This is the method that I added\n- (void)longPress:(UIView *)webView {&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress)];\n&nbsp;&nbsp;&nbsp;&nbsp;\n\/\/ Making sure the allowable movement isn&#039;t too narrow\n&nbsp;&nbsp;&nbsp;&nbsp;longPress.allowableMovement=100; \n\/\/ This is important - the duration must be long enough to allow taps but not longer than the period in which the scroll view opens the magnifying glass\n&nbsp;&nbsp;&nbsp;&nbsp;longPress.minimumPressDuration=0.3;\n\n&nbsp;&nbsp;&nbsp;&nbsp;longPress.delaysTouchesBegan=YES;\n&nbsp;&nbsp;&nbsp;&nbsp;longPress.delaysTouchesEnded=YES;\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;longPress.cancelsTouchesInView=YES; \/\/ That&#039;s when we tell the gesture recognizer to block the gestures we want\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;[webView addGestureRecognizer:longPress]; \/\/ Add the gesture recognizer to the view and scroll view then release\n&nbsp;&nbsp;&nbsp;&nbsp;[webView addGestureRecognizer:longPress];\n}\n\n\/\/ I just need this for the selector in the gesture recognizer.\n- (void)handleLongPress {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n}\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Great answer from Zubaba at Stackoverflow. I\u2019m using a webView to display colored and bolded text and I had the same problem. I put his solution into a method and call it just after I initialize the webView. I don\u2019t seem to need the delegate. \/\/ This is the end of the method where I &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1596\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Disable copy in UIWebView<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1596","post","type-post","status-publish","format-standard","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1596"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1596\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}