UIPresentationController changes size when another view controller is displayed on top of it
Asked Answered
M

1

6

I am presenting a modal view controller using UIPresentationController. I am setting the frame of presentedView less than the containView's bounds using 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 great unto this point.

Now, I present another view controller modally (default not custom) on top of the currently displayed modal view controller which takes up the entire screen. So, I have a custom modal view controller underneath the default modal view controller that covers the entire screen.

The problem is when I dismiss the top view controller thats covering the entire screen, my custom view controller shows up covering the entire screen as well. I want my custom view controller's size to remain the same (smaller than containerView). Is there any way that I can achieve this.

Any help would be appreciated

Milwaukee answered 25/9, 2015 at 23:56 Comment(2)
Maybe you can use autoLayout instead of hardcode the frame dimensions?Gorman
With iOS 12 I was able to solve this by changing the presentationStyle to overCurrentContext instead of currentContextHallo
A
17

I encountered the same issue. I couldn't solve it by adding constraints, and -[UIPresentationController containerViewWillLayoutSubviews] is called too late (after the dismiss animation is completed).

After some time I figured out that the problem seems to be that the presenting controller view is being removed from the view hierarchy when you present with the default UIModalPresentationFullScreen presentationStyle and added again with a full screen size when it has to be shown again.

In iOS 8, you can use UIModalPresentationOverFullScreen as the presentationStyle when presenting from the smaller controller. The system will not automatically remove the presenting controller's view then. (-[UIViewController viewWillDisappear:] and such, doesn't get called on the presenting controller when you do this though)

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

Autarky answered 28/10, 2015 at 7:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.