Tropical Software Observations

09 October 2009

Posted by Teo Choong Ping

at 9:13 AM

1 comments

Labels:

iPhone-sdk Tips: Prevent scrolling and bouncing of UIWebView

You may have a situation where you do not want the UIWebView to bounce or scroll when a user touches the view. There are 2 ways to do just that.

1. Embed Javascript function in the page itself

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

2. Set AllowsRubberBanding to NO


[(UIScrollView*)[webview.subviews objectAtIndex:0] setAllowsRubberBanding:NO];

(Discussion here)

1 comments:

willemst said...

RubberBanding is a private API. Your app will get rejected if you use it.

Instead, disable the scolling on the scrollview subview of the webview:

if ([(UIScrollView *)scrollview respondsToSelector:@selector(setScrollEnabled:)])
{
[(UIScrollView *)scrollview setScrollEnabled:NO];
}