presentViewController在iOS 6中工作,但在iOS 5中不显示视图

presentViewController在iOS 6中工作,但在iOS 5中不显示视图,ios,ipad,Ios,Ipad,我开始为iOS 6开发我的应用程序,并在那里运行,现在我必须确保它也支持iOS 5.1,这样它才能在iPad1上运行。该端口非常简单,尽管与iOS 6相比,iOS 5中仅支持横向更令人痛苦。我只剩下一个无法解决的问题 我有如下所示的开始屏幕布局,然后当你按下“执行”按钮时,它会显示另一个视图控制器,全屏。这是父视图控制器中“执行”按钮调用的代码 - (void)performButtonPressed:(UIImage *)notationImage { self.performView

我开始为iOS 6开发我的应用程序,并在那里运行,现在我必须确保它也支持iOS 5.1,这样它才能在iPad1上运行。该端口非常简单,尽管与iOS 6相比,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中预期会发生什么以及会做什么。

[自我呈现视图控制器:self.performViewController动画:是完成:无]
仅适用于iOS 6+版本


您必须使用
[自我呈现ModalviewController:controller动画:是]
我的解决方案是将modalPresentationStyle更改为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;
}

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