问题描述:如果使用以下代码在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, 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)];
        
        
    }

 

相关文章:

  • 2021-11-07
  • 2022-02-02
  • 2021-10-08
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
猜你喜欢
  • 2021-12-03
  • 2021-10-19
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
相关资源
相似解决方案