Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop UIWebView bouncing vertically in phonegap 3.0

Tags:

ios

cordova

Have tried many suggestions from this and other forums, including setting "DisallowOverscroll" to "true". Is this broken in phonegap 3.0 by any chance ?

like image 903
rysv Avatar asked Sep 14 '13 07:09

rysv


4 Answers

In the file AppDelegate.h, after initialized the MainViewController, you could disable this bouncing by set the scrollView class inside the webview by :

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    ....................

    self.viewController.webView.scrollView.bounces = NO;
    return YES;
}

The configuration value in the file config.xml was not used, I searched all in Cordova project.

like image 123
Vantoan8x Avatar answered Oct 18 '22 01:10

Vantoan8x


Make certain changes in config.xml,

If you are using it for Android, then use

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

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

And for IOS, use like

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

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

Hope this helps you.

EDIT

Do a cordova build after you have made changes in the config.xml file so that the changes affect to your project. The above steps would solve your problem only after you do a cordova build

like image 38
Ashis Kumar Avatar answered Oct 18 '22 01:10

Ashis Kumar


this is method i've used in xcode way. i dont know how to solve that issue in phonegap maybe this few codes give you idea

in viewdidload:

webView.scrollView.delegate = self;
[webView.scrollView setShowsHorizontalScrollIndicator:NO];



-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

if (scrollView.contentOffset.x > 0  ||  scrollView.contentOffset.x < 0 )
    scrollView.contentOffset = CGPointMake(scrollView.contentOffset.y, 0);

}

like image 1
Соёмбо Бат-Эрдэнэ Avatar answered Oct 18 '22 00:10

Соёмбо Бат-Эрдэнэ


For Cordova 3.x and above I believe you can set up your (void)webViewDidFinishLoad in MainViewController.m as follows :

- (void)webViewDidFinishLoad:(UIWebView*)theWebView {
    // Black base color for background matches the native apps
    theWebView.backgroundColor = [UIColor blackColor];
    theWebView.scrollView.bounces = NO;
    return [super webViewDidFinishLoad:theWebView];
}

Tested: Cordova 3.4, 3.5.

like image 1
Ally Avatar answered Oct 18 '22 02:10

Ally