iOS更改方向时更改UI的最佳方法

时间:2012-03-04 08:24:55

标签: ios user-interface orientation

更改方向时更改UI的最佳方法是什么?

例如,使用两个不同的UIView一个肖像和一个横向,并在方向更改时显示其中一个,或者使用一个UIView并更改UI控件的大小和位置?

还有其他想法吗?

2 个答案:

答案 0 :(得分:5)

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        NSLog(@"Change to custom UI for landscape");
    }
    else if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
        toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        NSLog(@"Change to custom UI for portrait");

    }
}

答案 1 :(得分:2)

我总是建议对视图控制器视图中的所有子视图使用autoresizingmask。正确设置后,所有视图都会从方向自动调整大小,您需要额外的旋转特定子视图(一个纵向视图和一个横向视图)。

相关问题