当另一个视图控制器显示在它上面时,UIPresentationController 会改变大小 [英] UIPresentationController changes size when another view controller is displayed on top of it

查看:15
本文介绍了当另一个视图控制器显示在它上面时,UIPresentationController 会改变大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIPresentationController 展示一个模态视图控制器.我使用以下方法将presentedView的框架设置为小于containView的边界:

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.

问题是当我关闭覆盖整个屏幕的顶视图控制器时,我的自定义视图控制器也会显示覆盖整个屏幕.我希望我的自定义视图控制器的大小保持不变(小于 containerView).有什么办法可以做到这一点.

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.

任何帮助将不胜感激

推荐答案

我遇到了同样的问题.我无法通过添加约束来解决它,并且 -[UIPresentationController containerViewWillLayoutSubviews] 调用太晚(在关闭动画完成后).

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).

一段时间后,我发现问题似乎是当您使用默认 UIModalPresentationFullScreen presentationStyle 和当必须再次显示时,再次添加全屏尺寸.

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.

在 iOS 8 中,当从较小的控制器进行演示时,您可以使用 UIModalPresentationOverFullScreen 作为 presentationStyle.系统不会自动移除呈现控制器的视图.(-[UIViewController viewWillDisappear:] 等,当您执行此操作时不会在呈现控制器上调用)

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)

您也可以使用 iOS 7 中提供的 UIModalPresentationCustom,但您必须提供自己的过渡动画.

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

这篇关于当另一个视图控制器显示在它上面时,UIPresentationController 会改变大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆