gpt4 book ai didi

lua - 如何制作一个可以加速滚动到所有方向的 ScrollView ?

转载 作者:行者123 更新时间:2023-12-04 20:36:14 25 4
gpt4 key购买 nike

Corona SDK 提供的原始 ScrollView 仅支持垂直和水平滚动,但不能同时进行。

如您所见,视频打击做到了这一点。但它不是免费的。那我该怎么做呢? https://www.youtube.com/watch?feature=player_embedded&v=ecAcUxex46c#t=74

非常感谢。

最佳答案

这是一个例子,你可以用图片代替我放的矩形:

local widget = require( "widget" )

local sceneGroup = display.newGroup();

-- Create scene
local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY)
local tabBarHeight = 25

-- Adjust background color for some themes
local backgroundColor = { 240/255 }


-- scrollView listener
local function scrollListener( event )
local phase = event.phase
local direction = event.direction

if "began" == phase then
--print( "Began" )
elseif "moved" == phase then
--print( "Moved" )
elseif "ended" == phase then
--print( "Ended" )
end

-- If the scrollView has reached its scroll limit
if event.limitReached then
if "up" == direction then
--print( "Reached Top Limit" )
elseif "down" == direction then
--print( "Reached Bottom Limit" )
elseif "left" == direction then
--print( "Reached Left Limit" )
elseif "right" == direction then
--print( "Reached Right Limit" )
end
end

return true
end

-- Create a scrollView
local scrollView = widget.newScrollView {
left = 20-ox,
top = 62,
width = display.contentWidth+ox+ox-60,
height = display.contentHeight-32-tabBarHeight-120,
hideBackground = false,
backgroundColor = backgroundColor,
--isBounceEnabled = false,
horizontalScrollingDisabled = false,
verticalScrollingDisabled = false,
listener = scrollListener
}
sceneGroup:insert( scrollView )

-- Insert an image into the scrollView
local background = display.newRect( 100, 100, 1200, 1200 )
background.x = background.contentWidth * 0.5
background.y = background.contentHeight * 0.5
scrollView:insert( background )

-------------------------------------------------------------------------
-- Insert various other widgets into scrollView to exhibit functionality
-------------------------------------------------------------------------

-- Radio button set
local radioGroup = display.newGroup()
local radioButton = widget.newSwitch {
left = 20,
style = "radio",
initialSwitchState = true
}
radioGroup:insert( radioButton )
radioButton.y = 50

local radioButton2 = widget.newSwitch {
style = "radio"
}
radioGroup:insert( radioButton2 )
radioButton2.x = radioButton.x+radioButton.width
radioButton2.y = 50
scrollView:insert( radioGroup )

-- Checkbox
local checkboxButton = widget.newSwitch {
style = "checkbox"
}
checkboxButton.x = radioButton2.x+radioButton2.width+20
checkboxButton.y = 50
scrollView:insert( checkboxButton )

-- On/off switch
local onOffSwitch = widget.newSwitch {
style = "onOff",
initialSwitchState = false
}
onOffSwitch.y = 50
scrollView:insert( onOffSwitch )

-- Stepper
local stepper = widget.newStepper {
left = 20,
top = 80,
initialValue = 4,
minimumValue = 0,
maximumValue = 25
}
scrollView:insert( stepper )

-- Progress view
local progressView = widget.newProgressView {
left = 130,
width = 125,
isAnimated = true,
}
scrollView:insert( progressView )
progressView.y = stepper.y
local currentProgress = 0.0
testTimer = timer.performWithDelay( 100, function( event )
currentProgress = currentProgress + 0.01
progressView:setProgress( currentProgress )
end, 50 )

onOffSwitch.x = progressView.x+12

关于lua - 如何制作一个可以加速滚动到所有方向的 ScrollView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35717819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com