2010-04-15 107 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