2011-08-12 25 views
1

我正在開發一個iPhone應用程序。 UIViewController中是否有任何默認狀態/訪問器,用於告知方向是否正在進行?UIViewController:識別方向正在進行

目前我做了以下:

一個BOOL成員的UIViewController子說isOrientationChangeInProgress

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
isOrientationChangeInProgress = YES; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
isOrientationChangeInProgress = NO; 
} 

有沒有什麼更好的辦法?

+1

爲什麼需要這個? – jtbandes

回答

0

Apple建議在willRotateToInterfaceOrientation:duration:之前啓動任何動畫,因此在調用該方法後不久就會發生旋轉。持續時間屬性告訴你需要多長時間didRotateFromInterfaceOrientation:一旦旋轉完成,或約幾秒鐘後的持續時間。

所以,我想你的布爾是事後的最好的事情。我不明白爲什麼你需要知道這一點,雖然;也許你想要的結果可以用不同的方式實現。你想做什麼?

0

你可以要求被告知設備的方向信息以及:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) 
               name:UIDeviceOrientationDidChangeNotification object:nil]; 

然後你得到告訴記者,在orientationChanged:當改變發生