简体   繁体   中英

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.

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.

I know this might be a little confusing but check the gif example below.

例

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.

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

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 .

You can simply add this to the viewDidLoad of your CustomPresentationController .

Alternatively you may also try modalPresentationStyle as "Over Current Context"

You can refer very good examples of how you can keep some part of VC as transparent here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM