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.