IOS屏幕旋轉
//在iOS5.1 和 之前的版本中, 我們通常利用 shouldAutorotateToInterfaceOrientation: //來單獨控制某個UIViewController的旋屏方向支持
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); }
//但是在iOS6中,這個方法被廢棄了,取而代之的是這倆個組合:
(BOOL)shouldAutorotate { return YES; }
(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }
//設置View Controller被Presented時的首選顯示方向。 //當view controller被presented顯示時,可能在一個特定的方向顯示最合適,如果其僅僅支持這一個方向 //可以在supportedInterfaceOrientations方法中簡單的返回此方向,但如果view controller支持多個方向顯示 //但在某一個方向顯示最佳,則可以通過重寫preferredInterfaceOrientationForPresentation方法來返回此方向 //這樣,當view controller被presented時,將會以preferredInterfaceOrientationForPresentation返回的方向顯示。 //注意:preferredInterfaceOrientationForPresentation返回的方向是supportedInterfaceOrientations中的一個。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
//如果整個應用所有view controller都不支持旋屏
- (NSUInteger)application:(UIApplication )application supportedInterfaceOrientationsForWindow:(UIWindow )window
{
return UIInterfaceOrientationMaskPortrait;
}
//獲取到“當前interfaceOrientation
//具體區別,可參見StackOverflow的問答:
//http://stackoverflow.com/questions/7968451/different-ways-of-getting-current-interface-orientation
controller.interfaceOrientation,獲取特定controller的方向
[[UIApplication sharedApplication] statusBarOrientation] 獲取狀態條相關的方向
[[UIDevice currentDevice] orientation] 獲取當前設備的方向</pre>