Button lua corona-如何禁用触摸事件小部件。newScrollView

Button lua corona-如何禁用触摸事件小部件。newScrollView,button,lua,scrollview,coronasdk,displayobject,Button,Lua,Scrollview,Coronasdk,Displayobject,我有一个widget.newScrollView组件和一个widget.newButton在它前面。不幸的是,当我点击我的按钮时,它也会调用我的ScrollView“tap”处理程序。如何阻止ScrollView获取此事件? 以下是我正在使用的一些代码: local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print( "Button was pressed and re

我有一个widget.newScrollView组件和一个widget.newButton在它前面。不幸的是,当我点击我的按钮时,它也会调用我的ScrollView“tap”处理程序。如何阻止ScrollView获取此事件? 以下是我正在使用的一些代码:

local function handleButtonEvent( event )
    if ( "ended" == event.phase ) then
        print( "Button was pressed and released" )
    end
    return true; **I tried this - but it had no effect**
end
已添加

local button1 = widget.newButton(
{
    label = "button",
    onEvent = handleButtonEvent,
    emboss = false,
    shape = "roundedRect",
    width = 400,
    height = 100,
    cornerRadius = 32,
    fillColor = { default={1,0,0,1}, over={1,0.1,0.7,1} },
    strokeColor = { default={1,0.4,0,1}, over={0.8,0.8,1,1} },
    strokeWidth = 4,
    fontSize=100;
}
我有一个display.NewImages数组和我的处理程序-如下所示:

local planets = {};
planets[1] = display.newImage( "planetHexs/001.png", _topLeft_x, _topLeft_y);
planets[2] = display.newImage( "planetHexs/002.png", _topLeft_x, _topLeft_y + _planet_height2 );
....

local scrollView = widget.newScrollView(
{
    top = 0,
    left = 0,
    width = display.actualContentWidth,
    height = display.actualContentHeight,
    scrollWidth = 0,
    scrollHeight = 0,
    backgroundColor = { 0, 0, 0, 0.5},
    verticalScrollDisabled=true;
}

for i = 1, #planets do
    local k = planets[i];
    scrollView:insert( k )
end

function PlanetTapped( num )
    print( "You touched the object!"..num );
end

for i = 1, #planets do
    local k = planets[i];
    k:addEventListener( "tap", function() PlanetTapped(i) end )
end
我得到这个打印日志:

Button was pressed and released

You touched the object2

必须在事件函数上返回
true
,以防止传播。这本质上告诉Corona事件已正确处理,不应再触发该事件的事件侦听器

“点击”
“触摸”
事件由不同的侦听器处理,因此,如果您希望在触摸按钮时停止点击,您还需要向按钮添加一个
“点击”
侦听器,该侦听器基本上只返回
true
,以防止或阻止点击事件

button1:addEventListener("tap", function() return true end)

由于按钮没有点击事件,点击事件只需通过按钮传递到按钮后面有“点击”事件的任何对象。

您必须在事件函数中返回
true
,以防止传播。这本质上告诉Corona事件已正确处理,不应再触发该事件的事件侦听器

“点击”
“触摸”
事件由不同的侦听器处理,因此,如果您希望在触摸按钮时停止点击,您还需要向按钮添加一个
“点击”
侦听器,该侦听器基本上只返回
true
,以防止或阻止点击事件

button1:addEventListener("tap", function() return true end)

由于按钮没有点击事件,点击事件只需通过按钮,到达按钮后面有“点击”事件的任何对象。

在提出新问题之前,请使用google。如果要停止事件传播,则应处理事件的最后一个事件处理程序必须返回true。只需将return true作为handleButtonEvent函数的最后一条语句…非常感谢,小猪:)我尝试了,但没有成功:(我添加了更多的代码,这可能会有所帮助:)请再多帮助一点:)您是否尝试过在按钮事件处理程序中使用onPress或onRelease而不是onEvent?点击似乎是另一个事件,因此在按钮的事件处理程序中返回true不会产生任何影响。我已更新了答案。您必须向按钮添加一个只返回true的点击侦听器,本质上只是为了阻止点击事件,而不是传播到按钮后面的对象。可能的重复请在提出新问题之前使用google。如果要停止事件传播,则应处理事件的最后一个事件处理程序必须返回true。只需将return true作为handleButtonEvent函数的最后一条语句…非常感谢,小猪:)我尝试了,但没有成功:(我添加了更多的代码,这可能会有所帮助:)请再多帮助一点:)您是否尝试过在按钮事件处理程序中使用onPress或onRelease而不是onEvent?点击似乎是另一个事件,因此在按钮的事件处理程序中返回true不会产生任何影响。我已更新了答案。您必须向按钮添加一个tap侦听器,该侦听器只返回true,本质上只是为了阻止tap事件,而不是传播到按钮后面的对象。