【发布时间】:2012-10-08 14:04:43
【问题描述】:
我是 Titanium Studio 移动开发的新手。我想知道是否可以将事件转移到视图的父视图。
例如,假设我在一个名为 parentView 的视图之上添加了一个名为 imgVw 的 imageview,我想将 imgVw 的触摸事件传递给 parentView。请让我知道是否可能。提前致谢。
【问题讨论】:
标签: iphone ios events titanium-mobile transfer
我是 Titanium Studio 移动开发的新手。我想知道是否可以将事件转移到视图的父视图。
例如,假设我在一个名为 parentView 的视图之上添加了一个名为 imgVw 的 imageview,我想将 imgVw 的触摸事件传递给 parentView。请让我知道是否可能。提前致谢。
【问题讨论】:
标签: iphone ios events titanium-mobile transfer
请试试这个:
一个简单的技巧是将子视图的touchEnabled属性设置为false,将事件传递给父视图。希望对您有所帮助。
【讨论】:
您可以创建自定义事件监听器。当用户触摸图像视图时,您可以触发该事件。你甚至可以将参数传递给事件。
在你的父视图中定义一个自定义事件监听器
Ti.App.addEventListener('imageTouch',function(e) {
//This `e` will hold the argument passed
});
现在当您触摸图像视图时
向您的 ImageView 添加一个 eventListener 以捕获触摸事件,
myImage.addEventListener('touch',function(e) {
//Now fire your custom event here, this will take you to the custom
// event defined in your parent view
Ti.App.fireEvent('imageTouch',{
touchArg:[e] // here we save your touch callback in an array `touchArg` and pass this to the custom eventListener.
});
});
希望有所帮助:)
【讨论】: