我不确定这是一个bug还是我可能做错了什么,但是当我在纵向模式下启动我的应用程序而不旋转设备时,我运行了以下代码
if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
NSLog(@"Portrait");
} else {
NSLog(@"Landscape");
}我返回Landscape,在我旋转设备并再次检查后,它返回了正确的值,所以当你第一次启动时,似乎返回的方向是错误的。这是一个已知的问题吗?
编辑:
即使我在AppDelegate中运行此代码,它也返回Landscape,即使我在纵向模式下启动也是如此
if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
NSLog(@"Portrait");
} else {
NSLog(@"Landscape");
}发布于 2012-09-20 14:34:02
这是因为在第一次启动时,它返回UIDeviceOrientationUnknown。它既不是肖像也不是风景。如果要检测用户界面方向,则应使用
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"landscape");
}else{
NSLog(@"portrait");
}发布于 2012-09-20 13:38:51
在您的Info.plist >支持的界面方向中,将项目“纵向(底部主页按钮)”拖到其他项目上。
发布于 2012-09-20 13:47:28
这是仅用于纵向模式的代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}https://stackoverflow.com/questions/12506567
复制相似问题