0
votes

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.

example

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

1
try self.automaticallyAdjustsScrollViewInsets = NOkarthikeyan
inside the image picker class or in the class in which I'm calling the presentation?Ivan Cantarino
can you add some code which shows how exactly are you setting the size of the VC which is presenting the image picker.Ganesh Somani
@karthikeyan it didn't workIvan Cantarino
@GaneshSomani yes I'll add some codeIvan Cantarino

1 Answers

0
votes

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