UIModalPresentationCurrentContext - rotation methods are not called

I am trying to present a VC on top of a VC using the UIModalPresentationCurrentContext to see the presentation behind it. Below is the code:

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 pressed, the rotation looks completely broken. Instead of spinning cleanly, he awkwardly stretches his eyes to fit the new orientation.

Also, when I subclass transparentViewController, I find that its viewwillautorotate methods are not called! (Despite the fact that it rotates in a convoluted animation mode)

Is the UIModalPresentationCurrentContext not rotatable? Anyway, around? Anyone else run into this issue?

+6
source share
1 answer

I believe the problem is that the original view controller cannot rotate, so your modal view controller is also locked from rotation. To get around this, you can display the original UIViewController CALAyer in UIImage using the renderInContext method. You can then put this in a UIImageView at the bottom of the view hierarchy in your modular controller. This will cause the view manager to be transparent, as you see what was behind it in the fake static image. Then, when you rotate the UIViewController you can manually apply the CGAffineTransform to the UIImageView so that the background remains in place and the content on top UIImageView freely.

0
source

All Articles