Okay, so display.contentCenterY = display.contentHeight * 0.5 according to the documentation:
https://docs.coronalabs.com/api/library/display/contentCenterY.html
However display.contentHeight are values taken from the config file which most likely look like this:
width = 320, height = 480,
So now your variable centerY becomes 480 * 0.5 = 240 and that is why it works on iPhone 4 because that is the height of that screen. However if you use an iPhone 5 the height is 568 but the display.contentHeight is still the same (480) as it takes the same value from the config file.
How can we fix this then?
First read this document: https://forums.coronalabs.com/topic/60994-image-does-not-center-after-added-to-scrollview/#entry316260
Now, implement data for each device or use this snippet in config.lua:
--calculate the aspect ratio of the device: local aspectRatio = display.pixelHeight / display.pixelWidth application = { content = { width = aspectRatio \> 1.5 and 320 or math.floor( 480 / aspectRatio ), height = aspectRatio \< 1.5 and 480 or math.floor( 320 \* aspectRatio ), scale = "letterBox", fps = 30, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3.0, }, }, }
Now this code will work on all devices:
local widget = require( "widget" ) local centerX = display.actualContentWidth \* 0.5 local centerY = display.actualContentHeight \* 0.5 local actualW = display.actualContentWidth local actualH = display.actualContentHeight local scrollView = widget.newScrollView { x = centerX, y = centerY, width = actualW, height = actualH, horizontalScrollDisabled = true, listener = scrollListener } local topBluePart = widget.newButton { x = centerX, y = centerY, width = actualW, height = 50, defaultFile = "button.png", onEvent = bob } topBluePart.anchorX = 0.5 topBluePart.anchorY = 0.5 scrollView:insert( topBluePart )
Best regards,
Tomas