【问题标题】:Webview events not firedWebview 事件未触发
【发布时间】:2015-07-25 19:28:44
【问题描述】:

我正在使用ds.slideMenu 小部件,它具有以下视图:

<Alloy>
<View id="containerview">
    <View id="leftMenu">
        <TableView id="leftTableView" />
    </View>
    <View id="movableview">
        <View id="shadowview">
            <View id="navview">
                <Button id="leftButton" />
            </View>
            <View id="contentview" />
        </View>
    </View>
</View>
</Alloy>

显示 webview 的视图如下:

<Alloy>
<View class="container">
  <WebView id="webview" url="myremoteurlhere" onLoad="construct"/>
</View>
</Alloy>

为了介绍 ds.slideMenu 的代码做了什么,下面是当你改变你的视图时会发生什么:

function rowSelect(e) {
  if (Alloy.Globals.currentView.id != e.row.customView) {
    $.ds.contentview.remove(Alloy.Globals.currentView);
    currentView = Alloy.createController(e.row.customView).getView();
    currentView.touchEnabled = true;
    Alloy.Globals.currentView = currentView;
    $.ds.contentview.add(currentView);
  }
}

movableview 有一个 addEventListener 用于 'touchstart'、'touchend'、'touchmove' 并且肯定会得到事件而不是我的 webview。现在,webview 加载没有问题,但在 iOS 模拟器上,触摸事件不起作用。点击加载的页面,没有任何反应。

有什么提示吗?

【问题讨论】:

标签: ios webview titanium titanium-alloy


【解决方案1】:

答案是将willHandleTouches webview 属性设置为false。 来自官方文档:

明确指定此 Web 视图是否处理触摸。 在 iOS 平台上,如果此 Web 视图或其任何父视图具有触摸侦听器,则 Titanium 组件会拦截所有触摸事件。这可以防止用户与本机 Web 视图组件进行交互。 将此标志设置为 false 以禁用默认行为。将此属性设置为 false 允许用户与本机 Web 视图进行交互,并且仍然尊重发送给其父级的任何触摸事件。当用户与 Web 视图本身交互时,不会生成任何触摸事件。 如果您想从 Web 视图接收触摸事件并且用户不需要直接与 Web 内容交互,请将此标志设置为 true。

所以

<WebView id="<mywebviewid>" willHandleTouches=false url="<myurlhere>"/>

将按预期工作。

【讨论】:

    猜你喜欢
    • 2022-08-02
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多