通常我會在用戶旋轉設備(主要處理視圖幀)時發生的動畫在willAnimateToInterfaceOrientation方法中。在它的框架的形式,它應該是這樣的:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
//NSLog(@"willAnimateRotationToInterfaceOrientation: %d", toInterfaceOrientation);
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
{
// portrait
}
else
{
// landscape
}
}
編輯:在我需要記住以供將來使用的設備旋轉的情況下,我成立了伊娃在一個名爲currentOrientation(類型爲int)我的視圖控制器類,然後這樣做:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
//NSLog(@"shouldAutorotateToInterfaceOrientation: %d", toInterfaceOrientation);
if (toInterfaceOrientation == UIDeviceOrientationPortrait || toInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown ||
toInterfaceOrientation == UIDeviceOrientationLandscapeLeft || toInterfaceOrientation == UIDeviceOrientationLandscapeRight)
{
currentOrientation = toInterfaceOrientation;
}
return YES;
}
然後同時運行在視圖控制器的方法,我知道該設備是在什麼方向
正如我所提到的觀點甚至還不設備方向更改時,實例化。 。方向改變爲橫向 - >用戶單擊顯示另一個視圖的按鈕 - >此新視圖被創建並顯示,但其默認位置是縱向方向 - >當顯示視圖時,我將重新排列在willAnimateRotationToInterfaceOrientation方法中的元素處於錯誤的位置。 – Craigt
您是否找到解決方案?我有同樣的問題。我在viewDidLoad中有肖像默認值,並且在willAnimateRotationtoInterfaceOrientation方法中設置了橫向和縱向框架,但是如果屏幕直接加載到橫向,則該方法永遠不會被調用。 – Ryan