[英]iOS - Presenting a view controller from a presented view controller changes its height
I've a custom transition between two controller that works close to the iOS mail app, which one stays on top of the other with some implemented scrolling behavior. 我在两个控制器之间进行了一个自定义过渡,该控制器与iOS邮件应用程序非常接近,一个控制器位于另一个控制器的顶部,并具有一些已实现的滚动行为。
If I present a new view controller from the Presented view controller which isn't full screen sized, and then I dismiss this new presented view controller, the previous Presented view controller changes its height and then resizes itself. 如果从非全屏显示的Presented视图控制器中呈现一个新的视图控制器,然后关闭此新的Presented视图控制器,则先前的Presented视图控制器会更改其高度,然后自行调整大小。
I know this might be a little confusing but check the gif example below. 我知道这可能有点令人困惑,但请查看下面的gif示例。
As you can see, If I present this custom image picker and then dismiss it, the view controller which presented it warps to full screen and then resizes to the initial value. 如您所见,如果我呈现此自定义图像选择器然后将其关闭,则呈现该图像选择器的视图控制器将扭曲到全屏,然后将其大小调整为初始值。
How can I prevent this from happening? 如何防止这种情况发生? I want the ViewController which presents the image picker keeps its height.
我希望呈现图像选择器的ViewController保持其高度。
After the dismiss you can see the resize happening. 解雇后,您可以看到正在调整大小。
Setting the presenting view controllers size 设置演示视图控制器的大小
Since it's a UIViewControllerAnimatedTransitioning
I create a custom presentation and the size it's set has it's own identity
由于它是一个
UIViewControllerAnimatedTransitioning
我创建了一个自定义演示文稿,其设置的大小具有其自己的identity
class CustomPresentationController: UIPresentationController {
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController!) {
super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
}
override var frameOfPresentedViewInContainerView: CGRect {
let containerBounds = self.containerView?.bounds
let origin = CGPoint(x: 0.0, y: ((containerBounds?.size.height)! * 0.05))
let size = CGSize(width: (containerBounds?.size.width)! , height: ((containerBounds?.size.height)! * 0.95))
// Applies the attributes
let presentedViewFrame: CGRect = CGRect(origin: origin, size: size)
return presentedViewFrame
}
override func containerViewWillLayoutSubviews() {
presentedView?.frame = frameOfPresentedViewInContainerView
}
}
Any hint? 有什么提示吗? thanks
谢谢
I think that is where the issue is. 我认为这就是问题所在。 You are forcing the frame size which is not working out.
您正在强迫无法解决的帧大小。 You should use something like
preferredContentSize
. 您应该使用诸如
preferredContentSize
东西。
You can simply add this to the viewDidLoad
of your CustomPresentationController
. 您可以简单地将其添加到
CustomPresentationController
的viewDidLoad
中。
Alternatively you may also try modalPresentationStyle
as "Over Current Context" 另外,您也可以尝试使用
modalPresentationStyle
作为“当前上下文”
You can refer very good examples of how you can keep some part of VC as transparent here 你可以参考你如何保持VC的某些部分是透明的很好的例子在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.