Hi,
I am working on one game. In this user can drag image from scrollview and use that image as stand alone. So I want to remove this image from ScrollView but not from screen. how it is possible?
Thanks
Hi,
I am working on one game. In this user can drag image from scrollview and use that image as stand alone. So I want to remove this image from ScrollView but not from screen. how it is possible?
Thanks
If you insert the image into another display group, it should leave the scrollView. Another option is to create a duplicate of the image and drag that, while hiding the version in the scrollView.
If you’re using Composer or Storyboard, you can simply insert it into the scene’s view group and it will take it out of the ScrollView. If not you can get the current stage which is the top most “group” and put it there to take it out of all groups.
Hi rob and nick_sherman ,
I want functionality like if user scroll scrollview in horizontal then scrollView scroll in horizontal, But if user move object in down side then it remove from scrollview and drag downside. How this functionality is possible?
Here is my code.
local widget = require( “widget” )
local screenGroup = display.newGroup()
– Create a ScrollView
local scrollView = widget.newScrollView
{
left = 0,
top = 0,
width = display.contentWidth,
height = display.contentHeight,
bottomPadding = 0,
horizontalScrollDisabled = false,
verticalScrollDisabled = true,
}
local function onRectangleTouch(event)
local t = event.target
if event.phase == “began” then
display.getCurrentStage():setFocus( event.target )
t.markX = t.x
t.markY = t.y
screenGroup:insert(event.target)
elseif event.phase == “moved” then
t.x = (event.x - event.xStart) + t.markX
t.y = (event.y - event.yStart) + t.markY
elseif event.phase == “ended” then
display.getCurrentStage():setFocus(nil)
end
return true
end
local rectangle = {}
for i=1,3 do
rectangle[i] = display.newRect( 50 + (i*60), 100, 50, 50 )
rectangle[i]:setFillColor(1,0,0)
rectangle[i]:addEventListener(“touch”,onRectangleTouch)
scrollView:insert( rectangle[i] )
end
screenGroup:insert(scrollView)
Thanks in advance.
Hi @SP Technolab,
Let me try to clarify, so I can help: with these rectangles inside the scrollView, when you touch them, they immediately “take control”, correct? Meaning, that the scrollView is “disabled” upon any touch of these rectangles, because they steal control from it? And so, the user can’t scroll horizontally once a rectangle is touched?
If so, I think the API that will help you is :takeFocus() (consider the example at the bottom of the page):
http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html
What this does, basically, is this:
When the user touches the object (rectangle for your case), it takes focus away from the scrollView.
If the user moves the touch 10 pixels in the vertical direction (you should change this to horizontal), this API sends control back to the scrollView, so the user can continue moving the scrollView.
Hopefully this makes sense.
Brent
Thank you Brent,
My problem is solved. i put condition for horizontal scroll. if user moves the touch 10 pixels in the horizontal direction as you suggest scorllView take focus and it works.
If you insert the image into another display group, it should leave the scrollView. Another option is to create a duplicate of the image and drag that, while hiding the version in the scrollView.
If you’re using Composer or Storyboard, you can simply insert it into the scene’s view group and it will take it out of the ScrollView. If not you can get the current stage which is the top most “group” and put it there to take it out of all groups.
Hi rob and nick_sherman ,
I want functionality like if user scroll scrollview in horizontal then scrollView scroll in horizontal, But if user move object in down side then it remove from scrollview and drag downside. How this functionality is possible?
Here is my code.
local widget = require( “widget” )
local screenGroup = display.newGroup()
– Create a ScrollView
local scrollView = widget.newScrollView
{
left = 0,
top = 0,
width = display.contentWidth,
height = display.contentHeight,
bottomPadding = 0,
horizontalScrollDisabled = false,
verticalScrollDisabled = true,
}
local function onRectangleTouch(event)
local t = event.target
if event.phase == “began” then
display.getCurrentStage():setFocus( event.target )
t.markX = t.x
t.markY = t.y
screenGroup:insert(event.target)
elseif event.phase == “moved” then
t.x = (event.x - event.xStart) + t.markX
t.y = (event.y - event.yStart) + t.markY
elseif event.phase == “ended” then
display.getCurrentStage():setFocus(nil)
end
return true
end
local rectangle = {}
for i=1,3 do
rectangle[i] = display.newRect( 50 + (i*60), 100, 50, 50 )
rectangle[i]:setFillColor(1,0,0)
rectangle[i]:addEventListener(“touch”,onRectangleTouch)
scrollView:insert( rectangle[i] )
end
screenGroup:insert(scrollView)
Thanks in advance.
Hi @SP Technolab,
Let me try to clarify, so I can help: with these rectangles inside the scrollView, when you touch them, they immediately “take control”, correct? Meaning, that the scrollView is “disabled” upon any touch of these rectangles, because they steal control from it? And so, the user can’t scroll horizontally once a rectangle is touched?
If so, I think the API that will help you is :takeFocus() (consider the example at the bottom of the page):
http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html
What this does, basically, is this:
When the user touches the object (rectangle for your case), it takes focus away from the scrollView.
If the user moves the touch 10 pixels in the vertical direction (you should change this to horizontal), this API sends control back to the scrollView, so the user can continue moving the scrollView.
Hopefully this makes sense.
Brent
Thank you Brent,
My problem is solved. i put condition for horizontal scroll. if user moves the touch 10 pixels in the horizontal direction as you suggest scorllView take focus and it works.