Springboard (horizontal page flip thingy from iOS)

469
Vote up!

This is a short and robust implementation of a springboard, using Corona's scrollView widget.
It supports two kinds of touch events: a quick touch and flip, or a slow page drag and release.

What's included:

  • springboard class (springboard.lua)
  • a working example, with 3 pages and updated page dots like on iOS (main.lua)

In a nutshell:

create a new springboard object

board = springboard.new(displayGroup, width, height, pageTotal, callback, params)
  • displayGroup: mandatory displaygroup the board is inserted to (change this group's x/y to move your springboard)
  • width/height: width and height of a single page
  • pageTotal: number of pages you can flip through
  • callback: function called everytime the springboard changes page
  • params: optional table, can contain values for 'backgroundColor' (rgb table, see-through if not set) and 'time' (time for flip animations, 200 is standard)

springboard properties

  • board.page : returns the currently selected page (between 1 and pageTotal)
  • board.view : returns the scrollView widget

adding content to the springboard

board.view:insert(content)

where 'content' refers to a display object or group

manually scrolling to a page

board:goToPage(page, time)
  • page: number between 1 and pageTotal
  • time: transition time, set to 0 for instantaneous (no transition)

Gotchas

This springboard is entirely based on the scrollView widget, see the doc for its limitations: http://docs.coronalabs.com/api/library/widget/newScrollView.html
When having problems using buttons inside a scrollView, see this doc: http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

Works with Corona build #: 
2014.2393
Contributor: 
Wim Coosemans