[英]How to check landscape and portrait mode on appdelegate?
i want to run app in landscape and portrait mode, 我想在横向和纵向模式下运行应用程序,
How to check landscape and portrait mode on Appdelegate? 如何在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
{
// 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. 但是在appdelegate类型的对象上找不到错误属性界面方向。
How can i do that? 我怎样才能做到这一点?
You should check the current orientation of your iPad using. 您应该使用检查iPad的当前方向。 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)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");
}
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
NSString *nibName = UIDeviceOrientationIsLandscape(orientation) ? @"Landscape" : @"Portrait";
NSLog(@"orientation is %@",nibName);
}
委托方向是我们在plist中指定的方向,如果我们没有在plist中指定任何方向,它将采用纵向模式默认。但是在委托中你只有不支持你必须添加的方向的关键窗口视图控制器或具有视图的任何导航控制器然后您可以调用这些功能,它们将为您的设备提供正确的方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.