-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPushSegue.swift
64 lines (48 loc) · 2.43 KB
/
PushSegue.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// PushSegue.swift
// Peach
//
// Created by Stephen Radford on 06/02/2016.
// Copyright © 2016 Cocoon Development Ltd. All rights reserved.
//
// Adapted from https://github.com/insidegui/GRPushSegue/
import Cocoa
class PushSegue: NSStoryboardSegue {
override func perform() {
if let source = sourceController as? NSViewController {
if let dest = destinationController as? NSViewController {
source.presentViewController(dest, animator: PushSegueAnimator())
}
}
}
}
class PushSegueAnimator: NSObject, NSViewControllerPresentationAnimator {
func animatePresentationOfViewController(viewController: NSViewController, fromViewController: NSViewController) {
viewController.view.frame = NSMakeRect(NSWidth(fromViewController.view.frame), 0, NSWidth(fromViewController.view.frame), NSHeight(fromViewController.view.frame))
viewController.view.autoresizingMask = [.ViewWidthSizable, .ViewHeightSizable]
fromViewController.view.addSubview(viewController.view)
fromViewController.addChildViewController(viewController)
let destinationRect = fromViewController.view.frame
NSAnimationContext.runAnimationGroup({ context in
context.duration = 0.3
context.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
viewController.view.animator().frame = destinationRect
}) {
if let vc = viewController as? StreamViewController, fc = fromViewController as? ConnectionsCollectionViewController {
fc.collectionView.hidden = true
vc.reloadAndScroll()
}
}
}
func animateDismissalOfViewController(viewController: NSViewController, fromViewController: NSViewController) {
let destinationRect = NSMakeRect(NSWidth(fromViewController.view.frame), 0, NSWidth(fromViewController.view.frame), NSHeight(fromViewController.view.frame))
NSAnimationContext.runAnimationGroup({ context in
context.duration = 0.3
context.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
viewController.view.animator().frame = destinationRect
}) {
viewController.view.removeFromSuperview()
viewController.removeFromParentViewController()
}
}
}