在iOS 6中,presentViewController可以正常运行,但在iOS 5中无法显示视图。

3

我开始为iOS 6开发我的应用程序,并使其在那里工作,现在我必须确保它也支持iOS 5.1,以便在iPad 1上运行。移植相当容易,不过仅支持横向方向比在iOS 6中容易得多。我只剩下一个无法解决的问题。

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

- (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,它会有点效果,但是我的全尺寸视图无法适应。

有什么想法吗?

开始布局: Starting screen layout

在过渡期间子视图的奇怪旋转。整个屏幕应该变暗,而不仅仅是一个视图: Weird rotation of subview during transition

预期发生的事情,并且在iOS 6中确实发生了。 What was expected to happen and does in iOS 6

2个回答

2

我想到了一种解决这个问题的方法,但我希望能找到一个真正的解决方案。

我的临时解决方案是将modalPresentationStyle更改为UIModalPresentationFormSheet。然后使用如何调整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;
}

-1

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

您必须使用 [self presentModalViewController:controller animated:YES]; 在以下版本中使用:


不,我不相信那是真的。苹果文档清楚地说明它“可在iOS 5.0及更高版本中使用”。 - John Holcroft

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接