0

I am making a NSPopover, and have made it so I can transition between view controllers with a sliding animation using a parent view controller with my view controllers as children. It works well, except before I added this, the popover automatically resized to my view's size, but now, the popover is stuck at a fixed size.

The code for creating the popover:

    self.homeVC = PopoverViewController(nibName: "PopoverViewController", bundle: nil)
    self.loginVC = SignInViewController(nibName: "SignInViewController", bundle: nil)

    self.containerView.view.wantsLayer = true

    self.containerView.view.frame = self.homeVC!.view.bounds

    self.containerView.addChildViewController(self.homeVC!)

    self.containerView.view.addSubview(self.homeVC!.view)

    popover.contentViewController = self.containerView

The code for transitioning the view controllers:

    self.loginVC!.view.frame = self.homeVC!.view.bounds
    self.containerView.addChildViewController(self.loginVC!)

    let transition: NSViewControllerTransitionOptions = .SlideLeft

    self.containerView.transitionFromViewController(self.homeVC!, toViewController: self.loginVC!, options: transition, completionHandler: { finished in
        self.homeVC!.view.removeFromSuperview()
        self.homeVC!.removeFromParentViewController()
        self.containerView.view.bounds = self.loginVC!.view.bounds
    })

Is there anyway that I can make the popover automatically resize to the size it is supposed to be after transitioning?

Thanks in advance.

AppleBetas
  • 88
  • 6
  • What if you just set the popover view's frame to the farm of the container view? – rocky Mar 30 '16 at 22:27
  • @rocky Sadly, that's not the problem. The popover does match the container view's size, but doesn't pay attention to the container view's child's size (set with constraints). I figured out that the problem was constraints and fixed it. Now I set the popover's size with constraints. Thanks for the idea, though. – AppleBetas Mar 30 '16 at 23:16

1 Answers1

-1

I was able to fix it by instead of explicitly setting the frame, setting constraints to make the container view match the child's size.

AppleBetas
  • 88
  • 6