i want to run app in landscape and portrait mode,
How to check landscape and portrait mode on Appdelegate?
I try to call
- (BOOL) isPad{
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
开发者_StackOverflow // Return YES for supported orientations
if ([self isPad]) {
NSLog(@"is pad method call");
return YES;
}
else
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
}
- (BOOL)isPadPortrait
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationPortrait
|| self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (BOOL)isPadLandscape
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
}
but gives error Property interface orientation not found on object of type appdelegate.
How can i do that?
You should check the current orientation of your iPad using. I would recommend you to check these conditions on every view and act according to the current orientation:
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
//Do what you want in Landscape Left
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
//Do what you want in Landscape Right
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
//Do what you want in Portrait
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do what you want in Portrait Upside Down
}
I hope this helps you. :)
Feel free to contact me if you require any help.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
NSString *nibName = UIDeviceOrientationIsLandscape(orientation) ? @"Landscape" : @"Portrait";
NSLog(@"orientation is %@",nibName);
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
{
NSLog(@"Lanscapse");
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
{
NSLog(@"UIDeviceOrientationPortrait");
}
}
The delegate orientation is the orientation that we specify in the plist ,if we not specify in any orientation in plist it will take the portrait mode default .But in delegate you have only the key window that doesn't support the orientation you have to add the viewcontroller or any navigation controller with a view then you can call these function and they will give your the proper orientation for the device.
精彩评论