Вращение приложения Master-Detail для DetailViewController не выравнивается, если пользователь поворачивается при просмотре MasterViewController - PullRequest
0 голосов
/ 17 ноября 2011

У меня есть простое приложение 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);
    }
}

Если iPhone не поворачивается до тех пор, пока не будет отображен контроллер DetailViewController, кнопки расположены правильно.Но если пользователь поворачивает iPhone при просмотре таблицы MasterViewController, а затем нажимает на элемент, когда открывается DetailViewController, кнопки расположены неправильно.

Так, как я могу или где я могу расположить кнопки изMasterViewController?Спасибо за помощь!

1 Ответ

0 голосов
/ 17 ноября 2011

Вы можете проверить interfaceOrientation свойство UIViewController в вашем viewDidLoad или viewWillAppear, например:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UIInterfaceOrientation orientation = self.interfaceOrientation;
    if (orientation == UIInterfaceOrientationLandscapeLeft)
    {   firstButton.frame = CGRectMake(20, 240, 50, 50);
        secondButton.frame = CGRectMake(390, 240, 50, 50);
    }
    else if (orientation == 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);
    }
}
...