How to prevent app running in phone-gap from scrolling vertically?

后端 未结 14 1788
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 17:42

I\'m trying out phone gap and I want my application to not scroll up and down when the user drags their finger across the screen. This is my code. Can anyone tell me why it\

相关标签:
14条回答
  • 2020-12-22 17:58

    At first what you have to do is you should add the event listener in body unload method.

    simply put this line in the touch move method.

    it won't scroll document.addEventListener("touchstart/touchmove/touchend"). Any one of these 3.

    function touchMove (event e) {
        e.preventDefault;
    }
    
    0 讨论(0)
  • 2020-12-22 18:01

    in your config file use

    <preference name="webviewbounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    
    0 讨论(0)
  • 2020-12-22 18:04

    Go native and add this line to the AppDelegate.m file

    self.viewController.webView.scrollView.scrollEnabled = false;
    

    Drop it in the - (BOOL)application:(UIApplication)application didFinishLaunchingWithOptions* section.

    0 讨论(0)
  • 2020-12-22 18:07

    You didn't say if this is a native app or a web app.

    If this is a native app you can turn off scrolling on the webview

    UIScrollView* scroll;  //
    for(UIView* theWebSubView in self.webView.subviews){  // where self.webView is the webview you want to stop scrolling.
        if([theWebSubView isKindOfClass:[UIScrollView class] ]){
            scroll = (UIScrollView*) theWebSubView;
            scroll.scrollEnabled = false;
            scroll.bounces = false;
        }
    }
    

    otherwise here is a link on the phonegap wiki for preventing scrolling. http://wiki.phonegap.com/w/page/16494815/Preventing-Scrolling-on-iPhone-Phonegap-Applications

    0 讨论(0)
  • 2020-12-22 18:08

    Changed UIWebViewBounce to DisallowOverscroll in 2.6.0

    0 讨论(0)
  • 2020-12-22 18:09

    For me it work's perfect, when i use the body-selector with jquery. Otherwise i was not able to open external links with Phonegap.

    $('body').on('touchmove', function(evt) {
        evt.preventDefault(); 
    })
    
    0 讨论(0)
提交回复
热议问题