presentViewController在iOS 6中工作,但在iOS 5中不显示视图
我开始为iOS 6开发我的应用程序,并在那里运行,现在我必须确保它也支持iOS 5.1,这样它才能在iPad1上运行。该端口非常简单,尽管与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
- (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”方法被调用并执行它的操作
[自我呈现视图控制器: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及更高版本中可用”