設(shè)備方向發(fā)生變化時,應用會收到信的方向信息,并根據(jù)相關(guān)設(shè)置決定是否感覺新的設(shè)備方向調(diào)整界面方向。
如果需要修改默認支持方向,則必須在相應的UIViewController中覆蓋supportInterfaceOrientations方法,該方法的默認實現(xiàn)類似于一下代碼:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { //判斷當前設(shè)備類型
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
如果需要在界面方向發(fā)生變化時之行某些操作,則可以在UIViewController中覆蓋willAnimateRotationToInterfaceOrientation: duration: 方法。在界面方向發(fā)生改變后,UIViewController會收到willAnimateRotationToInterfaceOrientation: duration: 消息,消息的第一個參數(shù)是新的界面方向。