【问题标题】:presentViewController working in iOS 6 but not displaying the view in iOS 5presentViewController 在 iOS 6 中工作,但在 iOS 5 中不显示视图
【发布时间】:2013-03-08 11:08:53
【问题描述】:

我开始为 iOS 6 开发我的应用程序并让它在那里工作,现在我必须确保它也支持 iOS 5.1,以便它可以在 iPad 1 上工作。移植非常简单,尽管只支持横向方向是与 iOS 5 中的简单程度相比,iOS 5 中的痛苦更大。我遇到了一个无法解决的问题。

我有如下所示的起始屏幕布局,然后当您按下“执行”按钮时,它应该以模态方式呈现另一个视图控制器,全屏。这是父视图控制器中执行按钮调用的代码。

- (void)performButtonPressed:(UIImage *)notationImage {
    self.performViewController = [[YHPerformViewController alloc] initWithImage:notationImage
                                                               recordingService:self.performanceRecordingService];

    self.performViewController.modalPresentationStyle = UIModalPresentationFullScreen;
    self.performViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:self.performViewController animated:YES completion:^{
        [self.performViewController startPerformance];
    }];
}

在 iOS 6 中这很好。在 iOS 5 中似乎调用了所有正确的代码:

  • 正在呈现的视图控制器上的 loadView
  • shouldAutorotateToInterfaceOrientation - 我返回 YES
  • 我的“startPerformance”方法被调用并执行它的操作

但是,视图实际上并没有出现在屏幕上,与层次结构更高的视图控制器关联的所有视图都保留在屏幕上(顶部的形状和导航控件)。只有当前视图控制器的视图会淡出。更奇怪的是,在过渡期间,该视图在淡出时旋转了 90 度。我在下面包含了一个屏幕截图。如果我将 modalPresentationStyle 更改为 UIModalPresentationFormSheet,除了我的全尺寸视图不合适的预期问题之外,它还可以工作。

有什么想法吗?

起始布局:

过渡期间子视图的奇怪旋转。整个屏幕也应该淡出,而不仅仅是一个视图:

在 iOS 6 中预期会发生什么以及做什么。

【问题讨论】:

    标签: ios ipad


    【解决方案1】:

    我想出了一个解决这个问题的技巧。但我很想找到一个真正的解决方案。

    我的 bodged 解决方案是将 modalPresentationStyle 更改为 UIModalPresentationFormSheet。然后使用How to resize a UIModalPresentationFormSheet? 中描述的 hack 的变体来获得所需大小的表单。

    - (void)performButtonPressed:(UIImage *)notationImage {
        self.performViewController = [[YHPerformViewController alloc] initWithImage:notationImage
                                                                   recordingService:self.performanceRecordingService];
    
        // This is a bit of a hack. We really want a full screen presentation, but this isn't working under iOS 5.
        // Therefore we are using a form sheet presentation and then forcing it to the right size.
        self.performViewController.modalPresentationStyle = UIModalPresentationFormSheet;
        self.performViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:self.performViewController animated:YES completion:^{
            [self.performViewController startPerformance];
        }];
        self.performViewController.view.superview.bounds = self.performViewController.preferredBounds;
    }
    

    这需要将视图控制器呈现给“preferredBounds”属性并将其包含在其 loadView 方法中。

    - (void)loadView {
    
        … // Usual loadView contents
    
        // Part of the hack to have this view display sized correctly when it is presented as a form sheet
        self.preferredBounds = self.view.bounds;
    }
    

    【讨论】:

      【解决方案2】:

      [self presentViewController:self.performViewController animated:YES completion:nil] 仅适用于 iOS 6+ 版本。

      你必须使用[self presentModalViewController:controller animated:YES];

      【讨论】:

      • 不,我不相信这是真的。 Apple 文档明确指出它“适用于 iOS 5.0 及更高版本”。
      猜你喜欢
      • 2013-03-03
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 2012-12-31
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多