viewWillTransitionToSize:withTransitionCoordinator:
似乎只有在界面實際上會改變大小,這意味着我們已經旋轉了90度。如果您的佈局上只有一個遮罩,只允許橫向旋轉180度,則界面大小不會更改,因此此方法似乎未被調用。
我圍繞着這一在我的應用程序通過,而不是註冊到工作的UIDeviceOrientationDidChangeNotification
通知,如:
(在我的視圖控制器的viewWillAppear
):
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
(一個在我viewWillDisappear
[記得要退訂] )
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
我deviceOrientationDidChange:
樣子:
- (void)deviceOrientationDidChange:(NSNotification *)notification {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:orientation duration:1.0];
}
我加載我的viewController作爲分段按鈕的視圖。在這種情況下,我沒有得到viewWillTransitionToSize:withTransitionCoordinator:被調用。你如何加載viewController? – Surendra 2014-10-07 22:10:09