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

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

问题描述

我使用UIPresentationController呈现模态视图控制器。我使用以下方法将presentView的框架设置为小于containsView的边界:

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

经过一段时间后,我发现问题似乎是当您使用默认的全屏显示样式呈现并且再次添加全屏大小时,正在从视图层次结构中删除呈现控制器视图它必须再次显示。

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 full screen presentation style 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 could 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 could also use UIModalPresentationCustom which is available in iOS 7, but then you'll have to provide your own transition animation.

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

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