UIModalPresentationCurrentContext - Rotation Methods not called
Asked Answered
E

1

6

I'm attempting to present a VC on top of a VC using UIModalPresentationCurrentContext in order to see the view behind it. The code below works:

UIViewController *transparentViewController = [[UIViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:transparentViewController animated:NO completion:^{
}];

However, when i rotate the device after the VC has been pushed the rotation looks completely messed up. Instead of cleanly rotating it stretches the view awkwardly to fit the new orientation.

Furthermore, when I subclass the transparentViewController I find that its viewwillautorotate methods aren't being called! (Even though it is rotating in its messed up animation way)

Is the UIModalPresentationCurrentContext style not meant to rotate? Is there anyway around this? Has anyone else run into this issue?

Enmity answered 14/2, 2013 at 20:26 Comment(2)
Did you find a solution to this? I am facing the same issue..Angelynanger
Same here. Solution?Terrific
V
0

I believe that the issue is related to the original view controller not being able to rotate, so your modal view controller is also blocked from rotating. To get around this you can render the original UIViewController's CALAyer in to a UIImage using the renderInContext method. Then you can place this in a UIImageView at the bottom of your view hierarchy in your modal view controller. This will have the effect that the view controller will appear transparent, since you are seeing what was behind it in a fake static image. Then when the UIViewController rotates you can manually apply a CGAffineTransform to the UIImageView to have the background stay in place while the content on top of it is free to rotate.

Venireman answered 19/2, 2013 at 5:23 Comment(2)
D, thanks for the reply. The original view controller in this case is able to rotate, however, it behaves the same regardless of whether it is or isn't allowed to rotate. The solution you propose is a good one, however, what if the view behind updates? It would be best to utilize the transparency. Also, wouldn't the CGAffineTransform on the screenshot still "rotate" to offset the device rotation, showing an animation that wouldn't happen if the background was clearly unable to rotate?Enmity
Ah I misunderstood about the original view controller being able to rotate. I'm not sure how to solve the problem then.Venireman

© 2022 - 2024 — McMap. All rights reserved.