0

我正在编写一个应用程序,我想根据方向显示不同的视图。例如,如果设备是纵向加载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;
 }

}

有了这个,我在 IB 中创建了 2 个视图并将出口连接到正确的视图。我也试过这个:

- (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。有任何想法吗?

4

3 回答 3

1

我发现以下 2 个(Apple)示例项目很有用:

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

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

另外,请记住,从设备的角度来看,还有面朝上和面朝下的方向;这让我失望了。

于 2010-09-13T16:15:51.747 回答
0

我必须问一个显而易见的问题:

您是否为 iPad 打开了屏幕方向锁定开关?

于 2010-06-27T03:49:08.207 回答
0

根据您尝试执行的操作,您可以在 IB 中设置界面以自动处理旋转。你可以调整组件的大小,移动图片和标签,诸如此类。这可能会做你想做的事......

于 2010-09-13T16:02:19.190 回答