未激发Webview事件



我正在使用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>

并且显示网络视图的视图如下:

<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有一个代表"touchstart"、"touchend"one_answers"touchmove"的addEventListener,并且肯定是在获取事件而不是我的网络视图。现在,webview加载没有问题,但在iOS模拟器上,触摸事件不起作用。点击加载的页面,什么也没发生。

有什么提示吗?

答案是willHandleToucheswebview属性设置为false。来自官方文件:

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

所以

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

将按预期工作。

最新更新