I created a view in the AppDelegate, that I add to the window like this:
[window addSubview:myView];
I wanna be able to check for the device orientation everytime I come back to this view, so I can make some modifications to it. How can I do that in the appDelegate?
You could implement one of these methods in the delegate to see when the application rotates:
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration;
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation;
Or just check the orientation of the UIApplication status bar as needed with:
[[UIApplication sharedApplication] statusBarOrientation];
The device orientation, which may or may not match the interface orientation, is:
[[UIDevice currentDevice] orientation];
Here is what I tried first when the app is loading for the first time in the didFinishLauching
[[NSNotificationcenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object: nil];
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(showScreen) withObject:nil afterDelay:0];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
-(void)showScreen {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || UIDeviceOrientationLandscapeRight) {
CGRect screenRect = [[UIScreen mainScreen] bounds];
}
}
The landscape is detected but the screenRect show width=768 and height=1024 (I'm in an Ipad device).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With