我在一个方法中有以下代码。当我在模拟器中运行这段代码时,调试器会跳过代码?我遗漏了什么?
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight))
{
} else {
}发布于 2009-05-30 18:56:29
更新2
这应该无关紧要,但请尝试打开方向通知:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];更新
我的错,我以为它是空的。
尝试删除或语句,只测试单一方向。看看能不能修好它。也许有一个支架问题或一些愚蠢的事情。
我在生产代码中使用了以下测试,因此您的技术应该可以工作:
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
}原始答案
您必须在if块中实际放入语句才能使其进入。
调试器足够智能,可以跳过空块。
发布于 2011-06-14 21:23:06
确定界面方向的最佳方法是查看状态栏方向:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if(orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown) {
//Portrait orientation
}
if(orientation == UIInterfaceOrientationLandscapeRight ||
orientation == UIInterfaceOrientationLandscapeLeft) {
//Landscape orientation
}UIDevice类基于加速度计测量方向,如果设备平放,它将不会返回正确的方向。
发布于 2009-12-01 14:49:55
请注意,这里有一个宏UIDeviceOrientationIsLandscape和UIDeviceOrientationIsPortrait,因此您可以这样做,而不是分别与LandscapeLeft和LandscapeRight进行比较:
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
}https://stackoverflow.com/questions/930075
复制相似问题