2013年6月8日 星期六

iOS 5 -> iOS 6 的變更:view 的指定支援旋轉 method

指定旋轉支援的方向:

iOS 5

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
}

到 iOS 6 後改為

//是否支援自動旋轉 
- (BOOL)shouldAutorotate {
    return YES; 
} 

//支援的方向 
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft; 
} 

//預設的方向 
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    
    return UIInterfaceOrientationPortrait; 
}

那與一開始在 Target 宣告有何不同?



在 Target 宣告時有點類似在 interface 裡宣告,
也就是如果 ViewController 沒有宣告上面那三個 method 時,
會自動套用在 Target 宣告的支援旋轉方向,
而寫在程式碼的三個 method 會把 Target 的宣告 override 掉,
使用時機是想要在各個 View 客制自己支援的旋轉方向。




更多資訊可參考 Apple 的文件 Supporting Multiple Interface Orientations:http://ppt.cc/jUZl