2010-07-02 63 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