2010-07-02 31 views
2

我在iPhone应用程序中使用委托方法进行自动旋转。iphone发生风景时的问题

-(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation{ 

    if(interfaceOrientation == UIInterfaceOrientationPortrait){ 
      [UIView beginAnimations:@"View Flip" context:nil]; 
      [UIView setAnimationDuration:0.2f]; 
      [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
      self..view.transform = CGAffineTransformMakeRotation(0); 
      self.view.bounds = CGRectMake(0,0,320,460); 
      [UIView commitAnimations]; 
      self.navigationBar.frame=CGRectMake(0, 0, 320, 44); 


     }else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 

      [UIView beginAnimations:@"View Flip" context:nil]; 
      [UIView setAnimationDuration:0.2f]; 
      [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
      CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2); 
      self.view.transform = transform; 
      CGRect contentRect = CGRectMake(10, -10, 480, 300); 
      self.view.bounds = contentRect; 
      [UIView commitAnimations]; 

      self.navigationBar.frame=CGRectMake(0, 0, 480, 32); 

     }else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){ 
      //navigationController.navigationBar.frame=CGRectMake(0, 0, 480, 34); 
      [UIView beginAnimations:@"View Flip" context:nil]; 
      [UIView setAnimationDuration:0.2f]; 
      [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
      CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14159/2); 
      self.view.transform = transform; 
      CGRect contentRect = CGRectMake(-10, -10, 480, 300); 
      self.view.bounds = contentRect; 
      [UIView commitAnimations]; 

      self.navigationBar.frame=CGRectMake(0, 0, 480, 32); 
     }else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ 
       return NO; 
     } 
     return YES; 
    } 

旋转为横向模式时,它正在开发iPhone OS3,但在iPhone OS4精致,界面显示不正确

Landscape

当旋转回纵向模式接口压缩... 。 Portrait

请问我建议我怎么解决?

由于
迪皮卡

+1

我不知道这是不是问题,但你有很多硬编码的数字 - 你应该尽量使用计算的值,只要你可以,而不是320你应该使用self.view.frame.size 。宽度; – deanWombourne 2010-07-02 08:15:29

回答

0

的CGRect contentRect = CGRectMake(-10,-10,480,300); self.view.bounds = contentRect;

你为什么要给-10,-10?任何具体的原因。这完全是由于帧不匹配。只需更改该框架并检查它。

+1

我设置(-10,-10)只是中毒的屏幕视图....我使用iPod(版本3.1.3)..在这个iPod上它工作正常......但在iPhone 4.0上,它是不工作。 – Deepika 2010-07-02 09:02:10

+1

iOS4有很多问题。因此,在3.0系列中工作正常的代码并不意味着必须适用于iOS4。我认为这是框架维护问题。只需更改框架,并更改所有子视图的背景颜色,而不是每个视图的确切框架。尝试一次.... – 2010-07-02 09:40:28