My app has an issue where if it starts up in landscape, then turn to portrait, all of the text sizes are wonky. For this reason, I want to force the app to launch and stay in Portrait until a point that I specify in code.
The I have put this in my willLoadMain, and it works to tell me where the device is oriented at launch. Plus you can see that if we are in landscape
- (void)willLoadMain:(id\<CoronaRuntime\>)runtime { //orientation fetches [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)) { NSLog(@"We are in Landscape"); //set the orientation to portrait [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; } else { NSLog(@"We are in Portrait"); }
Here, the idea is to ‘turn off’ landscape mode until a call from lua turns it on. To do the turn-off part, I was planning on responding to the following method with ‘NO’ if it’s landscape:
- (BOOL)shouldAutorotate;
The issue is that when I put any of the following delegate methods in ‘MyCoronaDelegate.mm’ and rotate, not one of the 6 methods gets called. I am putting them within the ‘@implementation MyCoronaDelegate’ context, and adding the method callouts to the header file within . Any ideas why these methods don’t get called? (header file at the very bottom)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { NSLog(@"GONNA ROTATE"); myCurrentOrientation = &toInterfaceOrientation; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations NSLog(@"GONNA ROTATE2"); return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { BOOL isPortraitOrientation; NSLog(@"DID ROTATE"); } -(NSUInteger)supportedInterfaceOrientations{ NSLog(@"OK WITH THIS?"); return UIInterfaceOrientationMaskPortrait; // etc } - (BOOL)shouldAutorotate { NSLog(@"GONNA ROTATE\_ios6"); UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; if (orientation==UIInterfaceOrientationPortrait) { // do something } return YES; } -(IBAction) deviceOrientationChanged:(id) sender{ NSLog(@"Device Orientation= %d",[[UIDevice currentDevice] orientation]); }
MyCoronaDelegate.h:
@protocol CoronaRuntime; @interface MyCoronaDelegate : NSObject\<CoronaDelegate\> { id\<CoronaRuntime\> corona\_runtime; UIViewController \*\_selectedViewController; UIInterfaceOrientation \*myCurrentOrientation; } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; -(NSUInteger)supportedInterfaceOrientations; -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; -(BOOL)shouldAutorotate; -(IBAction) deviceOrientationChanged:(id) sender; @end