2011-02-06 87 views
4

我在導航堆棧上有ViewControllers A和B. A不支持橫向,B確實。如果用戶在查看B時旋轉到橫向,然後點擊返回按鈕,則A現在處於橫向。我如何防止這種情況? A的shouldAutorotateToInterfaceOrientation方法有沒有很好的理由?如何只允許導航堆棧中的一個視圖旋轉?

+2

我不明白爲什麼Cocoa Touch在所有的自動交易業務中都走上了這麼長的路,但卻沒有考慮到這種簡單而且非常常見的情況。爲了把它放在那裏+1。 – epologee 2011-02-06 18:28:14

回答

2

這對視圖控制器來說真的很煩人。而且它似乎不適合自動旋轉。也許,最好從B的shouldAutorotateToInterfaceOrientation返回NO,然後手動執行視圖旋轉。然後,它會不會影響A.

+0

拉我的頭髮!你如何手動強制改變方向?問題是我需要實際改變方向,所以鍵盤顯示在正確的位置。 – 2013-11-20 15:55:07

1

是的,我恨太... 所有我找到解決它是由我自己來做到這一點:

- (void)myAutomaticRotation{ 
    if (A.view.frame.size.width > A.view.frame.size.height) { 
     [UIView beginAnimations:@"View Flip" context:nil]; 
     [UIView setAnimationDuration: 0.5f]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

     self.view.transform = CGAffineTransformIdentity; 
     self.view.transform = CGAffineTransformMakeRotation(M_PI/2); 
     self.view.bounds = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f); 
     A.view.frame = CGRectMake(0,0,320, 480); 
     [UIView commitAnimations]; 
    } 
} 

你可以調用myAutomaticRotation在主/超強的UIViewController當你瀏覽到A.view, 並在同一個地方,你應該使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

} 

在那裏你可以檢查(A,B)使用的視圖,並允許橫向模式只是對於B ...

luca

+0

感謝您的代碼在這裏。我認爲Max在每個viewController中分別處理旋轉的建議稍微清晰一些。 – initlaunch 2011-02-09 10:36:42

相關問題