2011-09-06 82 views
0

當方向更改時,我對UIView進行了一些更改。這工作正常。在手機方向已被切換後添加視圖時出現問題。這不會導致任何循環方法被調用,因此也不會給我機會進行更改。顯示視圖時的手柄方向

什麼是正確的處理方式,可能在ViewDidLoad?我能否在當時檢測當前的方向?

裸記住它,我需要做,所以我不一些小的改動要加載不同的筆尖或類似的東西

非常感謝你:)

編輯*只是清除事情:正如我所提到的,當設備方向改變時,視圖甚至還沒有實例化。方向改變爲橫向 - >用戶單擊顯示另一個視圖的按鈕 - >此新視圖被創建並顯示,但其默認位置是縱向方向 - >當顯示視圖時,我將重新排列在willAnimateRotationToInterfaceOrientation方法中的元素處於錯誤的位置。

回答

1

通常我會在用戶旋轉設備(主要處理視圖幀)時發生的動畫在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; 
} 

然後同時運行在視圖控制器的方法,我知道該設備是在什麼方向

+0

正如我所提到的觀點甚至還不設備方向更改時,實例化。 。方向改變爲橫向 - >用戶單擊顯示另一個視圖的按鈕 - >此新視圖被創建並顯示,但其默認位置是縱向方向 - >當顯示視圖時,我將重新排列在willAnimateRotationToInterfaceOrientation方法中的元素處於錯誤的位置。 – Craigt

+0

您是否找到解決方案?我有同樣的問題。我在viewDidLoad中有肖像默認值,並且在willAnimateRotationtoInterfaceOrientation方法中設置了橫向和縱向框架,但是如果屏幕直接加載到橫向,則該方法永遠不會被調用。 – Ryan