This article refer to http://bbs.9ria.com/thread-227539-1-1.html thank Hbnana great god
The first type of loading HTML file
Add the code to the WebView loading agent method.
Prohibit long press the address of the pop-up image, etc.
[self. WebView stringbyevaluatingjavascriptfromstring:@ "document.body.style.webkittouchcallout= ' None ‘;" ];
Disable Long Press Copy
[self. WebView stringbyevaluatingjavascriptfromstring:@ " Document.documentelement.style.webkituserselect= ' None '; ];
The second type of loading PDF file
Second case: If UIWebView loads a PDF document, see the
Loading PDFs with UIWebView should be the most convenient way to browse PDFs in iOS.
However, it may be possible for customers to consider safety issues and to prohibit the opening of the webview above
Long press the feature that appears to copy text or pictures. My last project client had this requirement,
To achieve this, I did study for a while. And finally found a very simple implementation
method, just add a few more lines of code.
Today to share with you, can give some people who are struggling with this problem to provide some help so the best,
If there is a better way to realize this feature, you are welcome to teach more ....
- NSString *path = [[NSBundle mainbundle] pathforresource:@ "sample" oftype:@ "PDF"];
- nsurlrequest* pdfrequest = [nsurlrequest requestwithurl:[nsurl Fileurlwithpath:path];
- [Self.pdfview Loadrequest:pdfrequest];
- Create a custom long-press gesture in viewdidload or where appropriate
- Uilongpressgesturerecognizer *longpress = [[[Uilongpressgesturerecognizer alloc] initwithtarget:self Action:nil] Autorelease];
- Longpress.delegate = self; Remember to add <UIGestureRecognizerDelegate> delegates to the. h file
- Longpress.minimumpressduration = 0.4; Why set 0.4 here, because as long as the greater than 0.5 is invalid, I like probably because the default step out of the magnifying glass gesture of the long-time is 0.5 seconds,
- If our custom gesture is greater than or less than 0.5 seconds, it's too late to replace his default gesture, which is just my guess. But better than 0.2.
- Seconds, because some PDFs have a bookmark jump function, which is too small to invalidate these features.
- [Self.pdfview addgesturerecognizer:longpress];
- The next step is to implement a delegate.
- #pragma mark-gesturerecognizerdelegate
- -(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer
- {
- return NO; Be sure to return NO here, as to why everyone should take a look at the documentation for this method.
- There is this delegate will be called multiple times when you press the NSLog, you can use the output Gesturerecognizer and Othergesturerecognizer
- Let's see what it is.
- }
UIWebView Disable long press the popup copy selection box