如何制作可以加速滚动到所有方向的滚动视图?

时间:2016-03-01 08:21:25

标签: lua scrollview corona

Corona SDK提供的原始滚动视图仅支持垂直和水平滚动,但它不能同时执行此操作。

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

非常感谢。

2 个答案:

答案 0 :(得分:1)

这是一个例子,你可以使用图片而不是我放的矩形:

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

答案 1 :(得分:0)

所有方向的拖动和缩放选项:

dplyr