ianrey palo
ianrey palo

Reputation: 61

Dragging in UIWebView

Is there a way to prevent a UIWebView from being dragged? Also, is there a way to actually overwride the common UIWebView functions such as highlighting?

Hope someone can answer me.

Thanks

Upvotes: 0

Views: 1752

Answers (3)

Saurabh
Saurabh

Reputation: 21

webview.scrollView.scrollEnabled = NO;

Upvotes: 2

Nick Weaver
Nick Weaver

Reputation: 47241

You can look up the scrollView of the webView and disable the scrolling with this code:

UIScrollView *scrollView = nil;
for(UIView *aView in webView.subviews){
    if([aView isKindOfClass:[UIScrollView class] ]){
        scrollView = (UIScrollView *)aView;
        scrollView.scrollEnabled = NO;
        scrollView.bounces = NO;
    }
}   

Upvotes: 1

Andre
Andre

Reputation: 4487

To prevent the drag:

<script type="text/javascript" language="javascript">

   document.ontouchmove = function(e) 
   {
          e.preventDefault(); 
   }

</script>

To override the highlighting:

<style type="text/css">

    body
    {
        -webkit-user-select: none;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
        -webkit-touch-callout: none;
    }

</style>

So, on the highlighting part:

  • The 1st line disables selection (like on text)
  • The 2nd line disables the actual highlight
  • The 3rd option disables the "popup" you see when you press an image for 2 seconds, asking if you'd like to download/save

Keep the ones you need.

Hope this helps :)

Upvotes: 0

Related Questions