Orientation Change Issue

Hi Everyone !

I`m just finishing the development of my app on Corona , and it is almost ready to go for de AppStore. 

But, I`m having a small issue on orientation changes.

Here is the deal : 

IF THE FIRST orientation change os the screen is LATERAL (pulling up some side of the device) , the iPad rotates, but the corona doesn`t. 

The subsequent rotations ocurrs naturally. And if the first rotation is natural ( rotation like the simmulator ) the error doesn`t ocurr.

Here is a video 

http://www.youtube.com/watch?feature=player_embedded&v=JKg9Pmmpv9w

The code is 

local function onOrientationChange( event )

  if event.type == “faceUp” or event.type == “faceDown” then

    rebuild()

  end

  if math.abs(event.delta) > 85 then

    rebuild()

  end

end

someone ?!?!

Hi @renato,

Are the “faceUp” and “faceDown” orientations what you intend? Unless I’m woefully mistaken, these are triggered if you flip the device entirely over, i.e. screen facing down (to earth) or up (to the sky). If you’re looking for orientation events of the rotation between landscape and portrait, they are different. See here:

http://docs.coronalabs.com/api/event/orientation/type.html

Is that the issue, or am I missing something in your design intent?

Brent

Hi Brent, 

The “faceUp” and “faceDown” were an attempt to fix the issue. no success.

You can see on the video that the FIRST orientation change is not happening ? the afterones are normally happening … 

but the issue is only triggered if the FIRST orientation change is made by pulling up some side of the ipad .  if you rotate the screen ( as on simmulator )  all goes normally . 

Hi there,

Here’s how I’d suggest debugging this.  We know Corona knows about the first orientation change, because the Corona content area does in fact rotate.  The only problem is that rebuild() isn’t being called.  So something must be going wrong with the onOrientationChange function.

Either (1) the onOrientationChange function isn’t being called at all (i.e., Corona isn’t reporting to you the orientation change event), or (2) your code within onOrientationChange isn’t handling the first rotation correctly.  It’s possible that (1) might happen if you don’t set up the orientation change listener right away.  But my guess is that it’s (2), and that it has something to do with how event.delta is being reported.

I’d suggest simply printing the event table and looking at the output in the Xcode console as you rotate the device.  You might also want to print out system.orientation as soon as your app starts or resumes as an additional piece of info.

  • Andrew

Hi, i printed it , 

The if the first orientation change is lateral i get  event.delta = 0 .

if the first rotation isn`t lateral , i get event.delta = 90 .

If i rotate it again  any directions and types , i get  even.delta = 90 …

:frowning:

Interesting.  What about the value of event.type?

  • Andrew

Apr 18 16:41:46 SUsersbferriDesktopSimpleSalesappetIpad-iPad SimpleSales[40260] <Warning>: type:  landscapeRight

Apr 18 16:41:46 SUsersbferriDesktopSimpleSalesappetIpad-iPad SimpleSales[40260] <Warning>: name : orientation

Apr 18 16:41:46 SUsersbferriDesktopSimpleSalesappetIpad-iPad SimpleSales[40260] <Warning>: delta : 0

Right, so the orientation change event is correctly reporting that the new orientation is landscapeRight.

 

What you could do is store a variable immediately on startup like this:

[lua]

deviceOrientation = system.orientation

[/lua]

 

This will store what orientation the device is in, even before any orientation changes have happened.  Then, in your orientation listener, do something like this:

 

[lua]

local function onOrientationChange( event )

   if not(deviceOrientation == event.orientation) then

      rebuild()

   end

 

   deviceOrientation = event.orientation

end

[/lua]

 

That way, deviceOrientation will always be in sync with the actual device orientation, and any time it changes, you’ll rebuild your content.

 

Hope that helps.

 

  • Andrew

someone ?!?!

Hi @renato,

Are the “faceUp” and “faceDown” orientations what you intend? Unless I’m woefully mistaken, these are triggered if you flip the device entirely over, i.e. screen facing down (to earth) or up (to the sky). If you’re looking for orientation events of the rotation between landscape and portrait, they are different. See here:

http://docs.coronalabs.com/api/event/orientation/type.html

Is that the issue, or am I missing something in your design intent?

Brent

Hi Brent, 

The “faceUp” and “faceDown” were an attempt to fix the issue. no success.

You can see on the video that the FIRST orientation change is not happening ? the afterones are normally happening … 

but the issue is only triggered if the FIRST orientation change is made by pulling up some side of the ipad .  if you rotate the screen ( as on simmulator )  all goes normally . 

Hi there,

Here’s how I’d suggest debugging this.  We know Corona knows about the first orientation change, because the Corona content area does in fact rotate.  The only problem is that rebuild() isn’t being called.  So something must be going wrong with the onOrientationChange function.

Either (1) the onOrientationChange function isn’t being called at all (i.e., Corona isn’t reporting to you the orientation change event), or (2) your code within onOrientationChange isn’t handling the first rotation correctly.  It’s possible that (1) might happen if you don’t set up the orientation change listener right away.  But my guess is that it’s (2), and that it has something to do with how event.delta is being reported.

I’d suggest simply printing the event table and looking at the output in the Xcode console as you rotate the device.  You might also want to print out system.orientation as soon as your app starts or resumes as an additional piece of info.

  • Andrew

Hi, i printed it , 

The if the first orientation change is lateral i get  event.delta = 0 .

if the first rotation isn`t lateral , i get event.delta = 90 .

If i rotate it again  any directions and types , i get  even.delta = 90 …

:frowning:

Interesting.  What about the value of event.type?

  • Andrew

Apr 18 16:41:46 SUsersbferriDesktopSimpleSalesappetIpad-iPad SimpleSales[40260] <Warning>: type:  landscapeRight

Apr 18 16:41:46 SUsersbferriDesktopSimpleSalesappetIpad-iPad SimpleSales[40260] <Warning>: name : orientation

Apr 18 16:41:46 SUsersbferriDesktopSimpleSalesappetIpad-iPad SimpleSales[40260] <Warning>: delta : 0

Right, so the orientation change event is correctly reporting that the new orientation is landscapeRight.

 

What you could do is store a variable immediately on startup like this:

[lua]

deviceOrientation = system.orientation

[/lua]

 

This will store what orientation the device is in, even before any orientation changes have happened.  Then, in your orientation listener, do something like this:

 

[lua]

local function onOrientationChange( event )

   if not(deviceOrientation == event.orientation) then

      rebuild()

   end

 

   deviceOrientation = event.orientation

end

[/lua]

 

That way, deviceOrientation will always be in sync with the actual device orientation, and any time it changes, you’ll rebuild your content.

 

Hope that helps.

 

  • Andrew

Hi,
I am facing the similar issue while running my app in both orientation.
I have printed the event.type and system.orientation in my orientation change function and it’s working on simulator but when i am checking consolelog in xcode it does not print anything, though the orientation is happening.
That does not matter for me, The actual problem is when i am using my app on device some times, my screen is displaying half(It happens only in portrait mode).
So i want to know the exact reason.
I am stuck here for last couple of days.
I am using corona version : 1134
Please help.
  
Here is my orientation function:
<lua>
function onOrientationChange( event )  
    print(“orientation change==”…event.type)
    
    print(“in orientation change function=”…system.orientation)
    
    if system.orientation == “portrait” or system.orientation == “portraitUpsideDown” then
        _G.port = 0
        displayText()
    else
        _G.port = 1
        displayText()
    end
end    
 
Runtime:addEventListener(“orientation”, onOrientationChange )
</lua>

Here is my screen shot:

When it displays ‘half’ like this, the device is in portrait mode but your app is rendering the content thinking that the device is in landscape.  If you rotate your device to landscape, wait a second, and then rotate it back to portrait, does it then render the content in portrait mode correctly?

If it does, then it sounds like you have the exact same issue as the original poster, in which case I would think the approach that I described earlier in this thread would work.  It’s important that you implement the approach I wrote exactly as I wrote it.  You need to store system.orientation into a separate variable (which I called deviceOrientation) in your main.lua, and use this to compare against the event.orientation in the orientation listener.

  • Andrew

Thanks aukStudios,
I did the same but didn’t success. I think i got the issue now. When I am using crawl space library in my project then it does not detect system.orientation and when I removed the crawl space library from my code it does detect system.orientation. Is there any alternative of crawl space library?
Can anyone tell me why it happens?
Any help will be appreciated.
Thanks,