2010-06-29 163 views

回答

2

下面的方法“返回是”将使方向改变,如果它是“返回否”方向不会改变。

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{ 

return YES; 

} 

一切顺利。

+0

这意味着它会自动旋转到所有的方向,这是应用程序的目标。如果你想限制方向,你可以返回给定方向(参数)是否等于[这些]之一(http://developer.apple.com/iphone/library/documentation/uikit/reference/UIApplication_Class/参考/#的reference.html // apple_ref/DOC/UID/TP40006728-CH3-SW5)。 – 2010-06-29 20:12:00

0

为了回答您的问题的第二部分,可以通过重写-willRotateToInterfaceOrientation:duration:方法添加逻辑以调整大小或位置的观点,例如:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (toInterfaceOrientation == UIDeviceOrientationUnknown || toInterfaceOrientation == UIDeviceOrientationFaceUp || toInterfaceOrientation == UIDeviceOrientationFaceDown) { 
     // do something here for these orientations 
    } 
    else { 
     // do something else for the remaining orientation types 
    } 
} 
0

如果您的视图控制器不是顶层视图控制器,从顶层视图控制器在我的顶层视图控制器的willRotateToInterfaceOrientation ...您的视图控制器可能无法收到消息...

:你必须将消息传递willRotateToInterfaceOrientation:持续时间:,我包括这行...(frameViewController是我的第二级视图控制器)

if (frameViewController) 
     [frameViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];