I've been following this tutorial on implementing custom view controller transitions in iOS 8 with UIPresentationController
, and so far it all makes sense, but I can't seem to get my view controller to be the right size.
In that tutorial, they have the following code:
class OverlayPresentationController: UIPresentationController {
let dimmingView = UIView()
override init(presentedViewController: UIViewController!, presentingViewController: UIViewController!) {
super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
dimmingView.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
}
override func presentationTransitionWillBegin() {
dimmingView.frame = containerView.bounds
dimmingView.alpha = 0.0
containerView.insertSubview(dimmingView, atIndex: 0)
presentedViewController.transitionCoordinator()?.animateAlongsideTransition({
context in
self.dimmingView.alpha = 1.0
}, completion: nil)
}
override func dismissalTransitionWillBegin() {
presentedViewController.transitionCoordinator()?.animateAlongsideTransition({
context in
self.dimmingView.alpha = 0.0
}, completion: {
context in
self.dimmingView.removeFromSuperview()
})
}
override func frameOfPresentedViewInContainerView() -> CGRect {
return containerView.bounds.rectByInsetting(dx: 30, dy: 30)
}
override func containerViewWillLayoutSubviews() {
dimmingView.frame = containerView.bounds
presentedView().frame = frameOfPresentedViewInContainerView()
}
}
I understand all of it, except for frameOfPresentedViewInContainerView
. That returns a size, but, if I remove presentedView().frame = frameOfPresentedViewInContainerView()
in containerViewWillLayoutSubviews
it doesn't work. Why do I have to have that line? You would think the function itself would be sufficient, otherwise I'd just implement a random size in the containerViewWillLayoutSubviews
method.