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

白昼怎懂夜的黑 提交于 2019-11-29 14:48:43

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/32792202/uipresentationcontroller-changes-size-when-another-view-controller-is-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!