ScrollView onResize

I set my app to support both portrait and landscape. I have a screen containing a scrollview. I set the anchorX and Y to 0 and set the scrollview x and y to “display.screenOriginY” and “display.screenOriginY” as well. And the width and height of the scrollview is “display.actualContentWidth” and “display.actualContentHeight”

I tried to add a runtime event of “resize” to resize and reposition the scrollview when rotate, but it doesn’t seem working.

I think I have the same problem in this archived thread: https://forums.coronalabs.com/topic/44938-newscrollview-does-it-support-resizing-for-orientation-changes-within-storyboardcomposer/

My Corona Build is: 2015.2802 (2015.12.31)

anyone have the same problem with solution?

Hi @boscotwcheung,

Which is the more specific issue? The positioning of the ScrollView after resize? Or is the resize event not working whatsoever?

Brent

resize event was fired. But I am not able to reset the position and size of the scrollview properly in the resize event.

I have the following setting for my scrollview:

scrollview.anchorX = 0.5

scrollview.anchorY = 0

scrollview.x = display.contentWidth * 0.5

scrollview.y = 200

scrollview.width = display.actualContentWidth

scrollview.height = display.actualContentHeight - 450

I did the same setting in the resize event as well. However, when I rotate, the scrollview is not in full width and y is 0, x is around display.contentWidth * 0.3. It didn’t show me any error or warning message but just not showing properly after rotate.

I tried to print(scrollview.y) at the end of the resize event, it is showing 200 to me. but not the same as what I saw on the screen.

Other display objects can be re-positioned and resized properly in the resize event. I don’t know what’s wrong with the scrollview.

is it corona’s bug?

Hi @boscotwcheung,

My guess is that it’s because of how you’re setting non-center anchors on the ScrollView, which is internally a display group, and anchoring display groups brings about certain usage differences.

One thing I can suggest is to download one of our more recent samples which features a slide-down ScrollView “info” box. The physics “Joints” one should work as a test (it’s located in your local Corona application folder as with other samples):

CoronaSDK-XXXX > SampleCode > Physics > Joints

Run the sample, tap on the little orange “i” (info) button in the upper right, and see how it slides the info box downward (and notice that it’s a ScrollView, not just a static box).

Now, go into it’s “build.settings” and add “landscape” and “landscapeLeft” to the supported orientations table. Re-run the sample, open the info slide-down, and then change the orientation. You’ll see how the ScrollView adapts to the new orientation.

If this is basically what you’re attempting to do, inspect the “sampleUI.lua” file inside the “SampleUI” folder and you’ll see how I coded that to work. Perhaps it can work as a basis for your project too.

Take care,

Brent

anyone have the same problem with solution?

Hi @boscotwcheung,

Which is the more specific issue? The positioning of the ScrollView after resize? Or is the resize event not working whatsoever?

Brent

resize event was fired. But I am not able to reset the position and size of the scrollview properly in the resize event.

I have the following setting for my scrollview:

scrollview.anchorX = 0.5

scrollview.anchorY = 0

scrollview.x = display.contentWidth * 0.5

scrollview.y = 200

scrollview.width = display.actualContentWidth

scrollview.height = display.actualContentHeight - 450

I did the same setting in the resize event as well. However, when I rotate, the scrollview is not in full width and y is 0, x is around display.contentWidth * 0.3. It didn’t show me any error or warning message but just not showing properly after rotate.

I tried to print(scrollview.y) at the end of the resize event, it is showing 200 to me. but not the same as what I saw on the screen.

Other display objects can be re-positioned and resized properly in the resize event. I don’t know what’s wrong with the scrollview.

is it corona’s bug?

Hi @boscotwcheung,

My guess is that it’s because of how you’re setting non-center anchors on the ScrollView, which is internally a display group, and anchoring display groups brings about certain usage differences.

One thing I can suggest is to download one of our more recent samples which features a slide-down ScrollView “info” box. The physics “Joints” one should work as a test (it’s located in your local Corona application folder as with other samples):

CoronaSDK-XXXX > SampleCode > Physics > Joints

Run the sample, tap on the little orange “i” (info) button in the upper right, and see how it slides the info box downward (and notice that it’s a ScrollView, not just a static box).

Now, go into it’s “build.settings” and add “landscape” and “landscapeLeft” to the supported orientations table. Re-run the sample, open the info slide-down, and then change the orientation. You’ll see how the ScrollView adapts to the new orientation.

If this is basically what you’re attempting to do, inspect the “sampleUI.lua” file inside the “SampleUI” folder and you’ll see how I coded that to work. Perhaps it can work as a basis for your project too.

Take care,

Brent