Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:05:49+00:00 2026-06-04T11:05:49+00:00

I have scrollview widget with one child (myrect) I want to detect the touch

  • 0

I have scrollview widget with one child (myrect)

I want to detect the touch ended event for “myrect” however currently it only detects the “began” phase !!

here is the complete code

 --main.lua
 local widget = require "widget"

 local myscrollview = widget.newScrollView{}

 local myrect = display.newRect(0, 0, display.contentWidth, 68)                  
 myrect:setFillColor(255,100,100,255)
 myscrollview:insert(myrect)

 local function ontouch(event)

    if event.phase == "ended" then
            print("event ended")
    end
end
myrect:addEventListener( "touch", ontouch )

what I need is a basic functionality it is strange that corona does not support that or maybe I am missing something

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:05:51+00:00Added an answer on June 4, 2026 at 11:05 am

    Thank you SatheeshJM your code for some how give me wrong result so when I click anywhere outside the rect the “touch ended event ” will be fired

    but finally I have the solution Just in case if anyone is interested

    here is the enhanced version of the solution

    Thanks to Danny http://developer.anscamobile.com/forum/2012/05/15/scrollview-problem

    and Jonathan Beebe for this helpful workaround https://gist.github.com/1590908

    local widget = require "widget"
    
    local myscrollview = widget.newScrollView{}
    
    local myrect = display.newRect(0, 0, display.contentWidth, 68)                  
    myrect:setFillColor(255,100,100,255)
    myscrollview:insert(myrect)
    
    local function ontouch(event)
    
        if event.phase == "moved" then
            local dx = math.abs( event.x - event.xStart )
            local dy = math.abs( event.y - event.yStart )
    
            if dx > 5 or dy > 5 then
                myscrollview:takeFocus( event )
            end
        elseif event.phase == "ended" then
        display.getCurrentStage():setFocus(nil)
                print("event ended")
        end
    
        return true
    end
    myrect:addEventListener( "touch", ontouch )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that ScrollView can have only one Child but in my case I
i have a scrollView. i want it to scroll only in one direction(VERTICAL). Is
I have a scrollview in which i am creating buttons programmatically. On touch, button
I have a horizontal ScrollView implemented and working. however, when I Scrol horizontally he
Actually i want to implement swipe left and right in UIScrollview. i have scrollview
I have a scrollView. There is an itemsControl in it. So I want to
I have a scrollview with 25 pages (pagingEnabled) and i want to put a
I have ScrollView which contains 10 buttons. When a activity is launched only first
I have a custom ScrollView (extended android.widget.ScrollView) which I use in my layout. I
i have a scrollview ,it include one textView, the textView have many lines,in other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.