Вращение iPad, любой способ загрузить пользовательский вид на основе ориентации? - PullRequest
0 голосов
/ 27 июня 2010

Я пишу приложение, в котором я хотел бы отображать различные виды в зависимости от ориентации. Например, если устройство находится в вертикальной загрузке pView, если в альбомной загрузке lView. Ниже приведен код, который я сейчас пробовал.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
 if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
      self.view = portrait;
}
 else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
      self.view = landscape;
 }

}

С этим я создал 2 вида в IB и соединил розетки с правым видом. Я также попробовал это:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
 if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
      self.view = portrait;
}
 else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
      lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
      [self.navigationController pushViewController:abo animated:NO];
      [abo release];

 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
      lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
      [self.navigationController pushViewController:abo animated:NO];
      [abo release];

 }

}

Код непосредственно выше работал для ipod, но не для ipad. Есть идеи?

Ответы [ 3 ]

1 голос
/ 13 сентября 2010

Мне пригодились следующие 2 (Apple) примера проектов:

http://developer.apple.com/library/ios/#samplecode/AlternateViews/Introduction/Intro.html

http://developer.apple.com/library/ios/#samplecode/WhichWayIsUp/Introduction/Intro.html

Кроме того, помните, что с точки зрения устройства есть ориентация вверх и вниз; это застало меня врасплох.

0 голосов
/ 13 сентября 2010

В зависимости от того, что вы пытаетесь сделать, вы можете настроить свой интерфейс в IB для автоматической обработки поворотов. Вы можете изменять размеры компонентов, перемещать картинки и метки, и все в таком духе. Это может делать то, что вы хотите сделать ...

0 голосов
/ 27 июня 2010

Я должен задать очевидный вопрос:

У вас включен переключатель блокировки ориентации экрана для вашего iPad?

...