gpt4 book ai didi

iphone - 启动时的 UIInterfaceOrientation

转载 作者:行者123 更新时间:2023-11-29 11:08:47 25 4
gpt4 key购买 nike

我不确定这是一个错误还是我可能做错了什么,但是当我在没有旋转设备的情况下以纵向模式启动我的应用程序并运行此代码时

if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
NSLog(@"Portrait");
} else {
NSLog(@"Landscape");
}

我返回Landscape,在我旋转设备并再次检查它返回正确的值之后,所以当您第一次启动时返回的方向似乎是错误的。这是一个已知问题吗?

编辑:

即使我在我的 AppDelegate 中运行此代码,它也会返回 Landscape,即使我以纵向模式启动也是如此

if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
NSLog(@"Portrait");
} else {
NSLog(@"Landscape");
}

最佳答案

那是因为在第一次启动时它返回 UIDeviceOrientationUnknown。它既不是肖像也不是风景。如果你想检测用户界面方向,你应该使用

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"landscape");
}else{
NSLog(@"portrait");
}

关于iphone - 启动时的 UIInterfaceOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12506567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com