Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Created April 9, 2012 14:54
Show Gist options
  • Save stonehippo/2344029 to your computer and use it in GitHub Desktop.
Save stonehippo/2344029 to your computer and use it in GitHub Desktop.
Prevent UIWebview "rubber band" scrolling in Phonegap apps on iOS
/*
Inserting the following into application:didFinishLaunchingWithOptions: in
the AppDelegate.m of your app will prevent the parent UIWebview for scrolling
with the "rubber band" bouncing effect, which can make the app feel more native.
*/
// Prevent the webview rubber-banding behavior (but allow other stuff to scroll)
[[[self.viewController.webView subviews] lastObject] setScrollEnabled:NO];
@stonehippo
Copy link
Author

Of course, there's a standard way to do this build into Cordova (duh). Set the value of the UIWebViewBounce key in Cordova.plist to "NO" to turn off the rubber-band bounce.

Not sure what version of PhoneGap/Cordova that showed up in.

@javierdechile
Copy link

in the lastest version have to edit the config.xml file:

<preference name="UIWebViewBounce" value="false" />

@olimungo
Copy link

Adding "UIWebViewBounce" didn't worked. I changed DisallowOverscroll in PhoneGap 2.0.7 and it worked for me:

<preference name="DisallowOverscroll" value="true" />

in config.xml

@stonehippo
Copy link
Author

@olimungo DisallowOverscroll is the new key. The old key is actually webviewbounce, so @javierdechile's example should have read:

Either value will work, though I recommend using the newer value as the older one is deprecated.

@rocco
Copy link

rocco commented Oct 11, 2013

funnily (or not) the old key "webviewbounce" is still present in cordova / phonegap 3.0.x this needs to be changed to "DisallowOverscroll" as it's apparently deprecated (no hints there...?) - cost me a few minutes just now. so maybe this helps someone else.

@ivansnek
Copy link

It worked, but in my application I need to scroll down/up, but without the rubber band rubber-band, and with this the overflow content is not visible, and I can`t scrolldow, does anybody know how to fix this?

@mnyamor
Copy link

mnyamor commented Jul 18, 2014

I'm using cordova version 3.5.0-0.2.6 and been having the same issue. This however seemed to fix the issue.
on your "CDVViewController.m file , you should add this when you Instantiate the WebView

if (!self.webView) {
[self createGapView];
webView.delegate = self;
webView.scalesPageToFit = YES;
[[webView scrollView] setBounces:NO];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment