2011-08-10 93 views
1

我想根据某些条件旋转ViewController。 shouldAutorotateToInterfaceOrientation的问题在于视图总是以纵向/横向方向开始(如在界面生成器中设置的那样),并且用户必须旋转iPad以使用正确的模式....我如何改变这种行为? 谢谢。以编程方式更改视图方向而不旋转ipad

回答

1

将变换应用于视图。

view.transform = CGAffineTransformMakeRotation(M_PI);

可以使用的UIView动画以动画的变化。

+0

我会尽力让你知道。谢谢。另一件事:这将使用Interf Builder中定义的这些自动调整规则吗? –

+0

不,上面的代码不会改变视图的大小,它只会旋转它。请注意,根据文档,应用了非身份变换的视图在框架属性中具有未定义的值。 – Jiri

1

您也可以尝试在您的info.plist添加此:

<key>UISupportedInterfaceOrientations</key> 
<array> 
    <string>UIInterfaceOrientationPortrait</string> 
    <string>UIInterfaceOrientationPortraitUpsideDown</string> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
    <string>UIInterfaceOrientationLandscapeRight</string> 
</array> 

来源:ipad default-landscape not displaying

0
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 

这将改变方向,以potrait模式,而旋转device.Likewise您可以使用 风景也

+0

这可行,但它不在api文档中,所以您可能违反了Apple对私人apis的规定,并且可能会在您使用该应用程序时拒绝您的应用程序。 – erik

+1

这个mehtod被弃用,不再存在........ –

相关问题