iphone - 如何防止在 phone-gap 中运行的应用程序垂直滚动?

标签 iphone ios cordova

我正在尝试手机间隙,我希望我的应用程序不会在用户将手指拖过屏幕时上下滚动。这是我的代码。谁能告诉我为什么它仍然允许滚动?

   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta name = "viewport" content = "user-scalable=no,width=device-width" />
    <!--<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />-->

    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

    <!-- iPad/iPhone specific css below, add after your main css >
    <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />        
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />       
    -->
    <!-- If you application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here -->
    <script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.min.js"></script>
    <script type="text/javascript" charset="utf-8">


    // If you want to prevent dragging, uncomment this section
    /*
    function preventBehavior(e) 
    { 
      e.preventDefault(); 
    };
    document.addEventListener("touchmove", preventBehavior, false);
    */

    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    for more details -jm */
    /*
    function handleOpenURL(url)
    {
        // TODO: do something with the url passed in.
    }
    */

    function onBodyLoad()
    {       
        document.addEventListener("deviceready",onDeviceReady,false);
    }

    /* When this function is called, PhoneGap has been initialized and is ready to roll */
    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
    for more details -jm */
    function onDeviceReady()
    {
        // do your thing!
        navigator.notification.alert("PhoneGap is working")
    }
    touchMove = function(event) {
        // Prevent scrolling on this element
        event.preventDefault();
    }

</script>
<style>
#container {
width:100%;
height:100%;
}
</style>

</head>

    <body onload="onBodyLoad()">
        <div id="container" ontouchmove="touchMove(event);">
        </div>
    </body>
</html>

最佳答案

如果您使用的是 Cordova 2.3.0+,请找到 config.xml 并添加以下行:

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

或在 Cordova 2.6.0+ 中:

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

关于iphone - 如何防止在 phone-gap 中运行的应用程序垂直滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6193016/

相关文章:

iphone - 发生 ARC 时发出警告?

ios - 使用 Storyboard 的条件转场

ios - 自定义单元格中的 UITextField 文本在滚动 UITableView 时发生变化

android - 亚马逊 iap 和 phonegap

iphone - 从 iphone 的不同 View Controller 调用函数

ios - 启用方向锁定时检测设备的实际方向 (iOS)

iphone - 将测试人员添加到 TestFlight

ios - 文件 “XXX” 不存在

ios - Cordova 在后台播放 YouTube 视频

iphone - 使用 Phonegap 和 Javascript 在运行时读取应用程序包中的文件