0

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

Ivan Cantarino
  • 3,058
  • 4
  • 34
  • 73

1 Answers1

0

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

Ganesh Somani
  • 2,280
  • 2
  • 28
  • 37
  • I'll try it out the way you said. If it doesn't work somehow I'll @ you for some tips ;) thank you – Ivan Cantarino Jun 05 '17 at 12:03
  • It didn't work as expected. I tried applying the `preferedContentSize` to the size I wanted and if went right except that it got clipped to the origin on the top left corner so it got an empty black bar at the bottom. I still somehow need to implement the `frameOfPresentedViewContainerView` so I can set its origin to the bottom left. I'm trying to create something similar to the iOS mail.app when you're creating a new e-mail, the animation itself with the gestures. – Ivan Cantarino Jun 05 '17 at 13:23
  • I am sorry but I believe your approach towards the solution is bit wrong. The view will resize post any viewcontroller being added and removed. Also for the empty black bar, are you sure you are using "Over Current Context" ? – Ganesh Somani Jun 06 '17 at 06:33