Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 72 lines (56 sloc) 2.65 KB
//
// Created by Pete Callaway on 26/06/2014.
// Copyright (c) 2014 Dative Studios. All rights reserved.
//
import UIKit
class CustomPresentationController: UIPresentationController {
lazy var dimmingView :UIView = {
let view = UIView(frame: self.containerView!.bounds)
view.backgroundColor = UIColor(white:0,alpha:0.5)
view.alpha = 0.0
return view
}()
override func presentationTransitionWillBegin() {
// Add the dimming view and the presented view to the heirarchy
self.dimmingView.frame = self.containerView.bounds
self.containerView.addSubview(self.dimmingView)
self.containerView.addSubview(self.presentedView())
// Fade in the dimming view alongside the transition
let transitionCoordinator = self.presentingViewController.transitionCoordinator()
transitionCoordinator.animateAlongsideTransition({(context: UIViewControllerTransitionCoordinatorContext!) -> Void in
self.dimmingView.alpha = 1.0
}, completion:nil)
}
override func presentationTransitionDidEnd(completed: Bool) {
// If the presentation didn't complete, remove the dimming view
if !completed {
self.dimmingView.removeFromSuperview()
}
}
override func dismissalTransitionWillBegin() {
// Fade out the dimming view alongside the transition
let transitionCoordinator = self.presentingViewController.transitionCoordinator()
transitionCoordinator.animateAlongsideTransition({(context: UIViewControllerTransitionCoordinatorContext!) -> Void in
self.dimmingView.alpha = 0.0
}, completion:nil)
}
override func dismissalTransitionDidEnd(completed: Bool) {
// If the dismissal completed, remove the dimming view
if completed {
self.dimmingView.removeFromSuperview()
}
}
override func frameOfPresentedViewInContainerView() -> CGRect {
// We don't want the presented view to fill the whole container view, so inset it's frame
var frame = self.containerView.bounds;
frame = CGRectInset(frame, 50.0, 200.0)
return frame
}
// ---- UIContentContainer protocol methods
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator transitionCoordinator: UIViewControllerTransitionCoordinator!) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: transitionCoordinator)
transitionCoordinator.animateAlongsideTransition({(context: UIViewControllerTransitionCoordinatorContext!) -> Void in
self.dimmingView.frame = self.containerView.bounds
}, completion:nil)
}
}