Reputation: 473
I started developing my app for iOS 6 and got it working there, now I am having to make sure it also supports iOS 5.1 so it will work on the iPad 1. The port was pretty easy, though only supporting landscape orientation is more of a pain in iOS 5 compared to how easy it is in 6. I'm left with one issue that I can't resolve.
I have the starting screen layout shown below and then when you press the 'Perform' button it should present another view controller modally, full screen. This is the code that the perform button calls in the parent view controller.
- (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];
}];
}
In iOS 6 this is fine. In iOS 5 all the right code seems to be called:
However the view doesn't actually appear on screen and all the views associated with view controllers higher up the hierarchy stay on screen (the shapes at the top and the navigation control). Only the view for the current view controller is faded out. Even weirder is that during the transition this view is rotated 90 degrees as it is fading out. I've included a screen capture below. If I change the modalPresentationStyle to UIModalPresentationFormSheet it kind of works apart from the expected issue of my full sized view not fitting.
Any thoughts?
Starting layout:
Weird rotation of subview during transition. Also the whole screen should be fading out, not just one view:
What was expected to happen and does in iOS 6.
Upvotes: 3
Views: 2401
Reputation: 1807
[self presentViewController:self.performViewController animated:YES completion:nil]
works in iOS 6+ versions only.
You have to use [self presentModalViewController:controller animated:YES];
in
Upvotes: -1
Reputation: 473
I have come up with a hack that solves this problem. But I would love to find a real solution.
My bodged solution is to change the modalPresentationStyle to UIModalPresentationFormSheet. Then use a variation on the hack described in How to resize a UIModalPresentationFormSheet? to get the form sheet to be the desired size.
- (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;
}
This requires the view controller being presented to a 'preferredBounds' property and to have this in its loadView method.
- (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;
}
Upvotes: 2