【问题标题】:How to add touch and scroll event on a button on a top of scroll view Corona?如何在滚动视图 Corona 顶部的按钮上添加触摸和滚动事件?
【发布时间】:2015-02-26 13:59:44
【问题描述】:

我正在电晕中创建关卡选择场景。为此,我使用了scrollview,并向scrollview 添加了一组按钮。

但我的问题是,当我触摸 scrollview 的背景时我可以滚动,但是当我触摸此按钮中的任何一个时,滚动视图没有滚动。

我需要处理按钮上的事件onpress 并滚动查看滚动视图
那么如果我触摸并按住按钮然后滚动手指,我如何滚动滚动视图有什么想法吗?

【问题讨论】:

  • 听起来你没有使用if event.phase == "ended" then...这会导致按钮在触摸时立即注册。
  • 是的,我已经将它用于点击事件,然后将我带到另一个看到的地方,所以我应该使用 event.phase == "began" 来滚动视图吗?

标签: lua coronasdk


【解决方案1】:

我已经通过此代码在按钮侦听器中使用takefocus 方法解决了我的问题

if ( phase == "moved" ) then
    local dy = math.abs( ( event.y - event.yStart ) )
    -- If the touch on the button has moved more than 10 pixels,
    -- pass focus back to the scroll view so it can continue scrolling
    if ( dy > 10 ) then
        scrollView:takeFocus( event )
    end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多