您的問題含糊不清,這是一般性解釋。您可以覆蓋下面提到的方法來處理方向下面提到的方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// return YES to supported orientation.
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
/* Subclasses may override this method to perform additional actions immediately
prior to the rotation. For example, you might use this method to disable view
interactions, stop media playback, or temporarily turn off expensive drawing or live
updates. You might also use it to swap the current view for one that reflects the new
interface orientation. When this method is called, the interfaceOrientation property
still contains the view’s original orientation.
*/
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
/*Subclasses may override this method to perform additional actions immediately after
the rotation. For example, you might use this method to reenable view interactions,
start media playback again, or turn on expensive drawing or live updates. By the time
this method is called, the interfaceOrientation property is already set to the new
orientation.*/
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
/*This method is called from within the animation block used to rotate the view.
You can override this method and use it to configure additional animations that should
occur during the view rotation. For example, you could use it to adjust the zoom level
of your content, change the scroller position, or modify other animatable properties
of your view.*/
}
不要檢查在viewDidLoad中或viewDidAppear設備的方向這樣
if([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft)
OR if(UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation))
,因爲很多時候它改變
在騎會帶來意想不到的結果,就像iPhone/iPad放在桌子上一樣(我曾經遇到過......非常討厭的問題)。
這apple developer link會給更多信息有關處理方向
- (空)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation時間:(NSTimeInterval)持續時間會打電話的時候設備方向變化 – Narayana 2012-03-12 07:16:45