问题描述:如果使用以下代码在iPad模拟器上进行判断横竖屏的话,运行正常,但是如果运行在真机上,结果一直运行else语句,也就是说判断无效。
if([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight)
{
[self.imageView setFrame:CGRectMake(0, 0, 704, 768)];
[self.cameraController setFrame:CGRectMake(0, 532, 768, 216)];
}
else {
{
[self.imageView setFrame:CGRectMake(0, 0, 704, 768)];
[self.cameraController setFrame:CGRectMake(0, 532, 768, 216)];
}
else {
[self.imageView setFrame:CGRectMake(0, 180, 768, 628)];
[self.cameraController setFrame:CGRectMake(0, 788, 768, 216)];
}
如果将以上代码换成以下代码就可以在真机上运行。以后在判断方向时,统一用“self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft”
if(self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
[self.imageView setFrame:CGRectMake(0, 0, 704, 768)];
[self.cameraController setFrame:CGRectMake(0, 532, 768, 216)];
}
else {
[self.imageView setFrame:CGRectMake(0, 180, 768, 628)];
[self.cameraController setFrame:CGRectMake(0, 788, 768, 216)];
}