4

在 Cordova CLI v3.4 中使用 ionicframework

我在 config.xml 文件中使用了以下首选项。

<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />

通过 CLI 和 XCode 编译似乎无法解决任何问题。

然后我搜索了DisallowOverscroll整个项目并确保所有值都设置为true

尽管在我看来,我仍然在接受橡皮筋。任何人都知道可能是什么问题?

谢谢!

4

2 回答 2

12

根据离子论坛上的这篇文章

“这是一个离子问题,而不是科尔多瓦问题。

 <ion-content
         has-bouncing="false"
         start-y="55"
         padding="true"
         has-tabs="true"
         has-header="true"
         >

使用该属性禁用指令has-bouncing上的反弹效果”ion-content

只需设置 attr has-bouncing="false",我不知道为什么这会覆盖 Cordova 配置设置。

于 2014-04-29T21:23:33.183 回答
0

您也可以在 HTML+JS 端执行此操作,前提是 HTML 文档高于 WebView 视口(在 JS 中也称为 window.height)。您可以通过在适当的时间(即当元素及其所有父元素在用户开始移动手指的方向上没有可滚动的内容时)在“touchmove”事件上调用 preventDefault 来做到这一点。

我将向您展示实际代码来执行此操作,而无需使用 jQuery ...但您必须自己实现 Q.addEventListener 和 Q.removeEventListener(或使用 jQuery)。

function _touchScrollingHandler(event) {
    var p = event.target;
    var pos;
    var scrollable = null;
    do {
        if (!p.computedStyle) {
            continue;
        }
        var overflow = p.computedStyle().overflow;
        var hiddenHeight = p.scrollHeight - p.offsetHeight;
        var s = (['hidden', 'visible'].indexOf(overflow) < 0);
        if ((s || p.tagName === 'HTML') && hiddenHeight > 0) {
            if ((Q.Pointer.movement.positions.length == 1)
            && (pos = Q.Pointer.movement.positions[0])) {
                var sy = Q.Pointer.getY(event)
                    + Q.Pointer.scrollTop();
                if ((sy > pos.y && p.scrollTop == 0)
                || (sy < pos.y && p.scrollTop >= hiddenHeight)) {
                    continue;
                }
            }
            scrollable = p;
            break;
        }
    } while (p = p.parentNode);
    if (!scrollable) {
        Q.Pointer.preventDefault(event);
    }
}

var Q = {
    preventTouchScrolling: function () {
        Q.addEventListener(window, 'touchmove', _touchScrollingHandler);
    },
    restoreTouchScrolling: function () {
        Q.removeEventListener(window, 'touchmove', _touchScrollingHandler);
    }
};
于 2014-10-23T03:39:29.840 回答