2010-08-18 82 views

回答

1

你可能在你這樣的事情,(我沒有方便的Xcode所以這個代碼可能不完全準確)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){ 
WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:@"NIBNAME" bundle:[NSBundle mainBundle]]; 
[self.navigationController pushViewController:newView animated:YES]; 
} 
+0

但隨後縱向方向看法仍然會在堆棧上,不是嗎?所以後退按鈕會指向錯誤的東西。 – 2010-08-19 18:09:12

+0

好點,你可以在視圖旋轉時隱藏導航欄,或者已經創建了視圖並將其淡入,並在旋轉發生時淡入其他視圖。 – octermircty 2010-08-19 22:21:35

1

這是正確的做法,我相信。我在我的應用程序使用它,它完美的作品

  1. 觸發上會旋轉,(直到旋轉阿尼姆即將開始等待)
  2. 用來橫向/縱向文件蘋果命名公約不應轉動(爲Default.png是默認-landscape.png如果你希望蘋果自動加載的風景版)
  3. 重新加載新的NIB
  4. 其重置self.view - 這將自動更新顯示
  5. ,然後它調用viewDidLoad(如果您手動重新加載NIB,Apple不會爲您調用此函數)

(NB stackoverflow.com這裏需要這句話 - 有代碼格式錯誤)

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) 
    { 
     [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@-landscape", NSStringFromClass([self class])] owner:self options:nil]; 

     [self viewDidLoad]; 
    } 
    else 
    { 
     [[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@", NSStringFromClass([self class])] owner:self options:nil]; 

     [self viewDidLoad]; 
    } 
}