UIPresentationController resizes when another view controller is displayed on it

I am presenting a modal presentation controller using the UIPresentationController. I set the frame of the presented view to be smaller than the borders of the keepView using the following method:

override func frameOfPresentedViewInContainerView() -> CGRect { let myDX = (self.containerView!.bounds.width - 600)/2 let myDY = (self.containerView!.bounds.height - 600)/2 return self.containerView!.bounds.insetBy(dx: myDX, dy: myDY) } 

Everything works fine up to this point.

Now I present another default view controller (default non-standard) on top of the current displayed modal controller, which occupies the entire screen. So, I have a custom modal view controller under a standard modular view controller that spans the entire screen.

The problem is that when I fire the top view controller that covers the whole screen, my custom view controller also shows up on the whole screen. I want my custom view controller size to stay the same (smaller than containerView). Is there a way I can achieve this.

Any help would be appreciated

+5
source share
1 answer

I ran into the same problem. I could not solve this by adding restrictions, but -[UIPresentationController containerViewWillLayoutSubviews] is called too late (after the termination animation is completed).

After a while, I realized that the problem is that the view of the controller view is removed from the view hierarchy when you present the default full-screen view style and added again with the full screen size when it should be shown again.

In iOS 8, you can use UIModalPresentationOverFullScreen as presentationStyle when presenting from a smaller controller. After that, the system will not automatically delete the view representation of the controller. ( -[UIViewController viewWillDisappear:] , etc., is not called when the controller submits, when you do it)

You can also use the UIModalPresentationCustom , which is available in iOS 7, but then you have to provide your own transition animation.

+10
source

Source: https://habr.com/ru/post/1232325/


All Articles