-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlideUpAnimator.swift
70 lines (51 loc) · 2.84 KB
/
SlideUpAnimator.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
65
66
67
68
69
70
//
// SlideUpAnimator.swift
// Govi
//
// Created by RomanC on 6/1/17.
// 2017 SapienSolutions, LLC.
/*
* Animation class that will slide both views(to and from views) to the right.
* Modify the duration variable to preference.
*/
import UIKit
class SlideUpAnimator: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate{
let durationStatic = 0.2
var presenting = true
var originFrame = CGRect.zero
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return durationStatic
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
//create the container the will controll the transition
let containerView = transitionContext.containerView
//set a variable to the fromView
let fromView = transitionContext.view(forKey: .from)!
//set a variable to the toView
let toView = transitionContext.view(forKey: .to)!
containerView.addSubview(fromView)
containerView.addSubview(toView)
//Give the original position/size of the fromView and toView
fromView.frame=CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height);
toView.frame=CGRect(x:0, y:0 + UIScreen.main.bounds.size.height, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
//Begin animation block
UIView.animate(withDuration: durationStatic, delay: 0.0, options: .curveEaseInOut,
animations: {
//Ending position/size of the frpmView and toView
fromView.frame=CGRect(x: 0, y: 0 - UIScreen.main.bounds.size.height, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height);
toView.frame=CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height);
},
completion: { _ in
//Completion handler that helps with gesture recognizers if you use them.(not required for regular segues)
print("ANIMATION HAS REACHED THE COMPLETION BLOCK")
if(transitionContext.transitionWasCancelled){
transitionContext.completeTransition(false)
UIApplication.shared.keyWindow?.addSubview(fromView)
}
else{
transitionContext.completeTransition(true)
}
}
)
}
}