0

我有一个始终是纵向的 iPhone 应用程序。但我需要旋转视图以显示表格。该按钮位于子视图中。我有这个代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

但是因为这个视图是从子视图中调用的,所以界面方向被忽略了。

有没有办法改变界面方向?

谢谢!

4

2 回答 2

0

您是否尝试过以下操作?

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;

于 2013-01-11T13:43:21.890 回答
0

您需要在要旋转的视图上设置变换,然后将其设置回身份变换。

这将在纵向和横向之间切换...

 UIView* viewToTransform = self.newview;
    if (CGAffineTransformIsIdentity(viewToTransform.transform)) {
        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
        viewToTransform.transform = transform;

    }else{
        viewToTransform.transform = CGAffineTransformIdentity;
    }

更好的是,将现有转换保存在一个属性中,以便您以后可以重置它(这将处理原始转换不是恒等转换的情况)。

于 2013-01-11T14:39:37.780 回答