-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathThirdViewControllerPresentAnimator.swift
More file actions
48 lines (35 loc) · 1.58 KB
/
ThirdViewControllerPresentAnimator.swift
File metadata and controls
48 lines (35 loc) · 1.58 KB
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
import UIKit
class ThirdViewControllerPresentAnimator: NSObject, UIViewControllerAnimatedTransitioning {
// MARK: Public
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.2
}
func animateTransition(context: UIViewControllerContextTransitioning) {
let fromNavigationController = context.viewControllerForKey(UITransitionContextFromViewControllerKey) as! UINavigationController
let fromView = fromNavigationController.topViewController!.view
let toView = context.viewForKey(UITransitionContextToViewKey)!
let fromViewButton = fromView.subviews.first as! UIButton
let toViewButton = toView.subviews.first as! UIButton
context.containerView()!.addSubview(toView)
toViewButton.transform = CGAffineTransformMakeScale(0, 0)
toView.backgroundColor = UIColor.clearColor()
UIView.animateWithDuration(
0.5,
animations: {
fromViewButton.transform = CGAffineTransformInvert(CGAffineTransformMakeTranslation(0, fromView.frame.height))
toView.backgroundColor = UIColor(hue: 0.14, saturation: 0.7, brightness: 1, alpha: 1)
},
completion: { _ in
context.completeTransition(!context.transitionWasCancelled())
UIView.animateWithDuration(0.5,
delay: 0,
usingSpringWithDamping: 0.5,
initialSpringVelocity: 0,
options: [],
animations: { toViewButton.transform = CGAffineTransformIdentity },
completion: nil
)
}
)
}
}