iPhone HTML5 App Scrolling Question

前端 未结 4 1160
有刺的猬
有刺的猬 2020-12-05 16:32

I don\'t know if this is even possible or what to Google to find it, but like you can add:



        
相关标签:
4条回答
  • 2020-12-05 16:44

    The solution for previous Cordova Versions is on following post: http://tripleshotsoftware.blogspot.ch/2012/09/stop-uiwebview-bounce-for-cordova-based.html

    change the MainViewController.m (or AppDelegate.m file in older versions of Cordova/Callback/PhoneGap).

    Look for webViewDidFinishLoad, and within that method add the following line:

    [[theWebView.subviews objectAtIndex:0] setBounces:NO];
    
    0 讨论(0)
  • 2020-12-05 16:51

    @JSW189

    if you delete this line:

    document.addEventListener( 'touchstart' , stopScrolling , false );
    

    Then it should work, I guess. I got the problem that I couldn't press button's any more, i try to delete this line above and it didn't scroll any more and I could press buttons.

    0 讨论(0)
  • 2020-12-05 16:57

    What you are calling overscroll is called bounce. Unfortunately there is not a documented way to turn off bounce in a UIWebView. You can look at UIScrollView for bounce related methods. A UIWebView owns a UIScrollView but does not expose it.

    To prevent horizontal scrolling, you just have to ensure that your web page fits within the viewport. One common cause of not fitting is a 100% width item when the body margin is not zero.

    You can completely prevent scrolling and bounce by adding touch event handlers to the document and calling preventDefault on the event. This will effectively disable bounce if your web page completely fits in the viewport.

    function stopScrolling( touchEvent ) { touchEvent.preventDefault(); }
    document.addEventListener( 'touchstart' , stopScrolling , false );
    document.addEventListener( 'touchmove' , stopScrolling , false );
    

    Edit:

    UIWebView is mostly private from the Objective-C side but fairly accessible from the javascript side. You can inject javascript if you do not control the content being loaded.

    0 讨论(0)
  • 2020-12-05 16:57

    If you're using Cordova 1.7+, just open the Cordova.plist file and set the key UIWebViewBounce to NO

    In Cordova 2.3+, this is now config.xml and you need to set it to false.

    0 讨论(0)
提交回复
热议问题