我有一個項目,其中旋轉事件在刪除/添加大量視圖/ viewControllers後停止觸發。它工作了一段時間,然後隨機添加到窗口的新視圖永遠不會獲取shouldAutorotateToInterfaceOrientation:調用。shouldAutorotateToInterfaceOrientation:在一段時間後無法調用
狀態欄無法旋轉,但視圖/視圖控制器功能正常(減旋轉)。此外,一次只有一個view/viewController添加到窗口中。我假設一箇舊的viewController被註冊爲鍵,但是添加到窗口的所有東西都是視圖控制器的子類,並且除了活動分配以外,沒有任何子類顯示在儀器分配中。
有沒有在應用程序委託或窗口找到哪個視圖控制器是關鍵的方法?
爲什麼shouldAutorotateToInterfaceOrientation:可能無法被調用嗎?
每個視圖控制器實施:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation { 返回YES; }
- (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)
interfaceOrientation duration: (NSTimeInterval) duration {
//manual rotation code
}
這裏是我使用在應用程序委託以改變根視圖控制器和所顯示的視圖中的代碼。
[UIView transitionWithView:new.view
duration:0.3
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//add new view
[self.window addSubview:new.view];
//play transition animation for old and new views
new.view.transform = CGAffineTransformConcat(new.view.transform, newEnd);
old.view.transform = CGAffineTransformConcat(old.view.transform, oldEnd);
//if old view is a "modal style" then keep it in front on new view
if([old conformsToProtocol:@protocol(PreloadableModalView)]) {
[self.window bringSubviewToFront:old.view];
}
}
completion:^(BOOL finished){
//remove old view
[old removeSubviews];
[old.view removeFromSuperview];
}];
ViewControllers不是「鍵」 - 一個單一的窗口是應用程序鍵。您不要將viewController添加到窗口 - 您添加視圖。你怎麼知道shouldAutoRotate沒有被調用? – Rayfleck 2011-06-01 14:07:19
我正在傳遞視圖[窗口addSubview:new.view]不是該控制器,這將允許UIWindow使用UIView的nextResponder屬性來查找我的viewController。 [蘋果關於呈現視圖控制器的文檔](http://bit.ly/jrMjE2)。 shouldAutorotate沒有被調用,因爲我在該函數中添加了一個NSLog,並且它從不觸發。我還添加了一個autorotate事件的觀察者,它註銷了它,但它並沒有幫助我,因爲如果我嘗試運行我的手動旋轉函數,狀態欄不會旋轉[[蘋果的文檔](http:/ /bit.ly/iQTXgk) – puppybits 2011-06-01 17:27:27
嗯。這裏涉及到UITabBar(你提到「根視圖控制器」)嗎?在過去,我不得不創建一個UITabBarController的自定義子類,並用下面的代碼覆蓋它的shouldAutorotateToInterfaceOrientation:{return self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];}這樣shouldAutoRotate實際上就會傳播到子視圖控制器。 – Rayfleck 2011-06-01 18:56:32