我想在 iPad 应用程序中显示启动画面。在此之前,我想获取当前设备方向的横向或纵向模式。我用过,
UIInterfaceOrientation orientation= [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft)
{
splachview=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
splachview.image=[UIImage imageNamed:@"Default-Landscape.png"];
splachview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
splachview.contentMode = UIViewContentModeTop;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.window addSubview:splachview];
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
splachview=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
splachview.image=[UIImage imageNamed:@"Default-Portrait.png"];
splachview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
splachview.contentMode = UIViewContentModeTop;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.window addSubview:splachview];
}
在 Appdelegate.m
中。始终仅在纵向模式下检测 UIInterface 方向。我在横向模式下启动了该应用程序,但控件始终只检测纵向模式。如何在 AppDelegate.m
中获取当前方向?请帮助我找到解决方案。提前致谢。
最佳答案
您不应该在 AppDelegate
上这样做,而应该在 UIViewController
上这样做。在 UIViewController
中,您可以通过 using the appropriate methods 正确知道设备的位置。 (配置 View 旋转设置部分)类(class)为您提供的内容。
关于ios - UIInterfaceOrientation 总是在 AppDelegate iPad 中返回 Portrait?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8816252/