Created
June 5, 2015 10:13
-
-
Save MickaelCruzDB/d8455e12dd6ea7ccb691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| import AppKit | |
| class MyCustomSwiftAnimator: NSObject, NSViewControllerPresentationAnimator { | |
| @objc func animatePresentationOfViewController(viewController: NSViewController, fromViewController: NSViewController) { | |
| let bottomVC = fromViewController | |
| let topVC = viewController | |
| topVC.view.wantsLayer = true | |
| topVC.view.alphaValue = 0 | |
| bottomVC.view.addSubview(topVC.view) | |
| var transition:CATransition = CATransition() | |
| transition.duration = 0.3 | |
| transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) | |
| transition.type = kCATransitionPush | |
| transition.subtype = kCATransitionFromRight | |
| transition.delegate = self | |
| NSAnimationContext.runAnimationGroup({ (transition) -> Void in | |
| transition.duration = 0.5 | |
| let existingView = NSView.self | |
| let nextView = NSView.self | |
| topVC.view.animator().replaceSubview(existingView.self(), with: nextView.self()) | |
| topVC.view.animator().alphaValue = 1 | |
| bottomVC.view.animator().alphaValue = 0 | |
| }, completionHandler: nil) | |
| } | |
| @objc func animateDismissalOfViewController(viewController: NSViewController, fromViewController: NSViewController) { | |
| let bottomVC = fromViewController | |
| let topVC = viewController | |
| topVC.view.wantsLayer = true | |
| topVC.view.layerContentsRedrawPolicy = .OnSetNeedsDisplay | |
| NSAnimationContext.runAnimationGroup({ (transition) -> Void in | |
| transition.duration = 0.5 | |
| let existingView = NSView.self | |
| let nextView = NSView.self | |
| topVC.view.animator().replaceSubview(existingView.self(), with: nextView.self()) | |
| topVC.view.animator().alphaValue = 0 | |
| bottomVC.view.animator().alphaValue = 1 | |
| }, completionHandler: nil) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment