如果用户在查看MasterViewController时旋转,则DetailViewController的Master-Detail App Autorotation未对齐

时间:2011-11-17 04:23:30

标签: iphone ios uitableview master-detail

我有一个简单的Master-Detail应用程序,带有MasterViewController和DetailViewController。在DetailViewController内部,我实现了以下代码,以便在旋转视图时,我的两个按钮位置正确。

  - (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation 
                                         duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {   firstButton.frame = CGRectMake(20, 240, 50, 50);
        secondButton.frame = CGRectMake(390, 240, 50, 50);
    }
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        firstButton.frame = CGRectMake(20, 240, 50, 50);
        secondButton.frame = CGRectMake(390, 240, 50, 50);
    }
    else
    {
        firstButton.frame = CGRectMake(80, 390, 50, 50);
        secondButton.frame = CGRectMake(190, 390, 50, 50);
    }
}

如果直到DetailViewController在视图中才动起iPhone,则按钮位置正确。但是,如果用户在查看MasterViewController表视图的同时旋转iPhone,然后点击一个项目,则当DetailViewController打开时,按钮位置不正确。

那么我如何定位MasterViewController中的按钮?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

您可以在viewDidLoad或viewWillAppear中查看interfaceOrientation的{​​{1}}属性,例如:

UIViewController