Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AddShowTransitionAnimator.swift
- // TVShowForecast
- //
- // Created by Thomas Krajacic on 3.11.2014.
- // Copyright (c) 2014 Thomas Krajacic. All rights reserved.
- //
- import Cocoa
- class FadeTransitionAnimator: NSObject, NSViewControllerPresentationAnimator {
- var hConstraints : [AnyObject]?
- var vConstraints : [AnyObject]?
- func animatePresentationOfViewController(viewController: NSViewController, fromViewController: NSViewController) {
- let bottomVC = fromViewController as NSViewController
- let topVC = viewController as NSViewController
- // make sure the view has a CA layer for smooth animation
- topVC.view.wantsLayer = true
- // set redraw policy
- topVC.view.layerContentsRedrawPolicy = .OnSetNeedsDisplay
- // switch to autolayout for resizing
- topVC.view.translatesAutoresizingMaskIntoConstraints = false
- // hide view initially
- topVC.view.alphaValue = 0.0
- // add view of presented viewcontroller
- bottomVC.view.addSubview(topVC.view)
- // add constraints
- self.hConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|[top]|", options: nil, metrics: nil, views: ["top":topVC.view])
- self.vConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|[top]|", options: nil, metrics: nil, views: ["top":topVC.view])
- bottomVC.view.addConstraints(self.hConstraints!)
- bottomVC.view.addConstraints(self.vConstraints!)
- // Do some CoreAnimation stuff to present view
- NSAnimationContext.runAnimationGroup({ (context) -> Void in
- context.allowsImplicitAnimation = true
- // fade duration
- context.duration = 1.3
- // move into place
- topVC.view.alphaValue = 1.0
- var transition:CATransition = CATransition()
- transition.type = kCATransitionMoveIn
- transition.subtype = kCATransitionFromRight
- transition.delegate = self
- }, completionHandler: {
- })
- }
- func animateDismissalOfViewController(viewController: NSViewController, fromViewController: NSViewController) {
- let bottomVC = fromViewController as NSViewController
- let topVC = viewController as NSViewController
- // make sure the view has a CA layer for smooth animation
- topVC.view.wantsLayer = true
- // set redraw policy
- topVC.view.layerContentsRedrawPolicy = .OnSetNeedsDisplay
- // Do some CoreAnimation stuff to present view
- NSAnimationContext.runAnimationGroup({ (context) -> Void in
- context.allowsImplicitAnimation = true
- // fade duration
- context.duration = 1.3
- //move top view to the left
- topVC.view.alphaValue = 0.0
- }, completionHandler: {
- // remove view
- topVC.view.removeFromSuperview()
- })
- // The VC is deallocated
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement