将事件转移到父视图(iPhone钛工作室)



我是Titanium Studio的移动开发新手。我想知道是否可以将事件转移到视图的父视图中。

例如,假设我有一个imageView,即在视图顶部添加了iMGVW,即parentView,我想将imgvw的触摸事件传递给parentview。请让我知道是否可能。预先感谢。

请尝试:

一种简单的技术是将儿童视图的 touchenabled 设置为 false ,将事件传递给父视图。希望它有帮助。

您可以创建一个自定义eventlistener。当用户触摸图像视图时,您可以发射该事件。您甚至可以将论点传递给事件。

在您的父视图中定义自定义eventlistener

Ti.App.addEventListener('imageTouch',function(e) {
  //This `e` will hold the  argument passed
});

现在触摸图像视图

将EventListener添加到您的ImageView以捕获触摸事件,

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.
     });
 });

希望有帮助:)

相关内容

最新更新