【问题标题】:iPad Rotation, Any Way To Load Custom View Based On Orientation?iPad Rotation,任何方式来加载基于方向的自定义视图?
【发布时间】:2010-06-26 22:49:58
【问题描述】:

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

【问题讨论】:

    标签: iphone ipad sdk orientation iphone-sdk-3.2


    【解决方案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

    另外,请记住,从设备的角度来看,还有正面朝上和正面朝下的方向;这让我大吃一惊。

    【讨论】:

      【解决方案2】:

      我要问一个显而易见的问题:

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

      【讨论】:

      • 不,我正在尝试根据方向加载不同的视图。
      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多