How To Change Orientation in CoronaCards

Hi, 

I and others have asked this before, but I’ll ask again in the hope someone responds with anything:

What is the correct way to change orientation when using CoronaCards?

Orientation changes work flawlessly in normal built Corona apps, an app message can be sent from a native app to the coronaView to detect the orientation change. But for whatever reason the width and height values are maintained portrait no matter what gets changed. 

Can anyone please explain how we are  expected to do this?

Thanks, 

Thomas

Are you on iOS or Android?

Both. We’re building equivalent native apps for both platforms

What Engineering is saying is that since Corona Cards is designed to be a view in a native app, the CoronaView is like any other native object, it has an X, Y width and heigh that’s always in portrait orientation. There isn’t a concept of orientation at the view level.

You could detect the orientation on the native side and then send an event to the view so you know that the orientation changed. 

Rob

We are already doing that, but when our resize methods are called, they expect (like it would be with a standard Corona build) the width and height to correspond to the new orientation.
What actually happens is the width x height values remain as 1080 x 1920.

We can’t seem to find a way around this

I ran into similar issue when I changed my orientation from portrait to landscape; when in landscape it maintains the portrait width. The reason why this is happening is due to the fact; in iOS when the orientation changes the iOS view is just transformed and not actually rotated.

Below is the code that actually worked for me:

- (void)viewDidAppear:(BOOL)animated { \_coronaController = [[CoronaViewController alloc] init]; [self addChildViewController:\_coronaController]; \_coronaView = (CoronaView \*)\_coronaController.view; CGRect appFrame = [UIScreen mainScreen].bounds; \_coronaView.frame = CGRectMake(0, 0, appFrame.size.height, appFrame.size.width); [self.view addSubview:\_coronaView]; // Transparent background \_coronaView.backgroundColor = [UIColor clearColor]; \_coronaView.opaque = NO; AppDelegate \*appDelegate = (AppDelegate \*)[UIApplication sharedApplication].delegate;; [appDelegate setShouldRotate:YES]; NSNumber \*value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; [\_coronaView setNeedsLayout]; [\_coronaView run]; }

Here’s the key points:

  • Got the main screen bounds
  • Set the frame size (passed height value to width and width value to height). Mine x and y was always at 0. So I set it to 0; If your’s is different interchange x and y values when you pass to CGRectMake
  • Rotated the view
  • added “setNeedsLayout”
  • Done

Took me a while to figure this out. Finally the above changes did work.

Are you on iOS or Android?

Both. We’re building equivalent native apps for both platforms

What Engineering is saying is that since Corona Cards is designed to be a view in a native app, the CoronaView is like any other native object, it has an X, Y width and heigh that’s always in portrait orientation. There isn’t a concept of orientation at the view level.

You could detect the orientation on the native side and then send an event to the view so you know that the orientation changed. 

Rob

We are already doing that, but when our resize methods are called, they expect (like it would be with a standard Corona build) the width and height to correspond to the new orientation.
What actually happens is the width x height values remain as 1080 x 1920.

We can’t seem to find a way around this

I ran into similar issue when I changed my orientation from portrait to landscape; when in landscape it maintains the portrait width. The reason why this is happening is due to the fact; in iOS when the orientation changes the iOS view is just transformed and not actually rotated.

Below is the code that actually worked for me:

- (void)viewDidAppear:(BOOL)animated { \_coronaController = [[CoronaViewController alloc] init]; [self addChildViewController:\_coronaController]; \_coronaView = (CoronaView \*)\_coronaController.view; CGRect appFrame = [UIScreen mainScreen].bounds; \_coronaView.frame = CGRectMake(0, 0, appFrame.size.height, appFrame.size.width); [self.view addSubview:\_coronaView]; // Transparent background \_coronaView.backgroundColor = [UIColor clearColor]; \_coronaView.opaque = NO; AppDelegate \*appDelegate = (AppDelegate \*)[UIApplication sharedApplication].delegate;; [appDelegate setShouldRotate:YES]; NSNumber \*value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; [\_coronaView setNeedsLayout]; [\_coronaView run]; }

Here’s the key points:

  • Got the main screen bounds
  • Set the frame size (passed height value to width and width value to height). Mine x and y was always at 0. So I set it to 0; If your’s is different interchange x and y values when you pass to CGRectMake
  • Rotated the view
  • added “setNeedsLayout”
  • Done

Took me a while to figure this out. Finally the above changes did work.

1 Like