2010-04-15 103 views
0

蘋果爲iPad演示了Photo's。在他們的演示中,他們說你可以翻轉iPad並翻轉圖像。風景模式:翻轉iPad時翻轉圖像

這個結果如何實現?

我一直在閱讀有關UIInterfaceOrientation了一整天,我迷路了

任何幫助,將不勝感激。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; 
// NSLog(@"orientation: %@", [orientation) 
if(orientation==UIInterfaceOrientationPortrait ||orientation==UIInterfaceOrientationPortraitUpsideDown) { 
    //Code 
    return NO; 
} 
if (orientation==UIInterfaceOrientationLandscapeRight ||orientation==UIInterfaceOrientationLandscapeLeft) { 
    //Code 
    return YES; 
} 
return NO; 
} 

回答

0

您在UIViewController子類中實現:

- (BOOL)shouldAutorotateToDeviceOrientation:... { 
    Return YES; 
} 

而且大部分的UIKit管理它都爲你的時間。

+0

謝謝,但你怎麼知道它翻轉的時間? (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];}} \t \t // NSLog的(@ 「取向:%@」,[取向) 如果(取向== UIInterfaceOrientationPortrait ||取向== UIInterfaceOrientationPortraitUpsideDown){ \t \t //代碼 \t \t返回NO; \t} \t如果(取向== UIInterfaceOrientationLandscapeRight ||取向== UIInterfaceOrientationLandscapeLeft){ \t \t //代碼 \t \t返回YES; \t} \t return NO; } – 2010-04-15 18:29:12

+0

我測試了它,它似乎沒有做任何翻轉。我甚至不確定何時翻轉。 – 2010-04-15 18:29:58

+0

(大部分時間)您不關心視圖是否翻轉,設備會爲您處理旋轉。如果你的控制器在tab/nave控制器中,你需要確保所有的視圖控制器都從這個方法返回true。 – 2010-04-15 18:40:43