你的问题很模糊,这是一个一般性的解释。您可以覆盖下面提到的方法来处理方向变化
超越以下提到的方法
- (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 放在桌子上(我经历过这个......非常讨厌的问题)。
这个 苹果开发者链接将提供有关处理方向的更多信息