简体   繁体   English

iOS-从显示的视图控制器中呈现视图控制器会更改其高度

[英]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 . 您可以简单地将其添加到CustomPresentationControllerviewDidLoad中。

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.

相关问题 iOS /自动版式:取消已演示的控制器后,更改为演示视图 - IOS/Autolayout: Change to Presenting View After Presented Controller Dismissed 在iOS中从提供的视图控制器推送视图 - Push View from Presented View Controller in iOS 如何在呈现的View Controller和呈现的View Controller之间建立关系? - How to setup a relationship between the presenting View Controller and the presented View Controller? 呈现视图 controller 位于呈现视图 controller 下方 - Presented view controller place under presenting view controller 使用CAShapeLayer遮罩呈现的视图控制器,也遮罩呈现的视图控制器 - masking presented view controller with CAShapeLayer also mask the presenting view controller 如何暂时隐藏同时呈现视图控制器的呈现视图控制器 - How to temporarily hide a presented View controller that is also presenting a view controller 呈现视图 controller 也可以是呈现视图 controller 吗? - Can a presented view controller also be a presenting view controller? iOS - 关闭在其视图之外触摸的呈现视图控制器 - iOS - Dismiss presented view controller touching outside its View 如果从过流上下文视图控制器呈现错误呈现视图控制器 - Wrong presenting view controller if presented from an over-current-context view controller 如何在没有用户能够看到呈现视图的情况下使用模态视图控制器启动iOS应用程序? - How to start an iOS app with a modal view controller already presented without the user being able to see the presenting view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM