-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationFactory.swift
More file actions
105 lines (95 loc) · 4.38 KB
/
Copy pathAnimationFactory.swift
File metadata and controls
105 lines (95 loc) · 4.38 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// AnimationFactory.swift
// We4G
//
// Created by aviv-inmanage on 15/08/2019.
// Copyright © 2019 Inmanage. All rights reserved.
//
import Foundation
import UIKit
enum AnimationFactory {
typealias Animation = (UITableViewCell, IndexPath, UITableView) -> Void
/// function for moviing cell up with fade interval
/// let animation = AnimationFactory.makeFadeAnimation(duration: 0.5, delayFactor: 0.05)
///
/// - Parameters:
/// - rowHeight: CGFloat responsible for the mobing height
/// - duration: TimeInterval responsible for the duration
/// - delayFactor: Double determing the time to start
/// - Returns: return Animation which is typealias which animation need to to create the animation
static func makeFadeAnimation(duration: TimeInterval, delayFactor: Double) -> Animation {
return { cell, indexPath, _ in
cell.alpha = 0
UIView.animate(
withDuration: duration,
delay: delayFactor * Double(indexPath.row),
animations: {
cell.alpha = 1
})
}
}
/// function for moviing cell up with fade interval
/// let animation = AnimationFactory.makeMoveUpWithBounce(rowHeight: cell.frame.height, duration: 1.0, delayFactor: 0.05)
///
/// - Parameters:
/// - rowHeight: CGFloat responsible for the mobing height
/// - duration: TimeInterval responsible for the duration
/// - delayFactor: Double determing the time to start
/// - Returns: return Animation which is typealias which animation need to to create the animation
static func makeMoveUpWithBounce(rowHeight: CGFloat, duration: TimeInterval, delayFactor: Double) -> Animation {
return { cell, indexPath, tableView in
cell.transform = CGAffineTransform(translationX: 0, y: rowHeight)
UIView.animate(
withDuration: duration,
delay: delayFactor * Double(indexPath.row),
usingSpringWithDamping: 0.4,
initialSpringVelocity: 0.1,
options: [.curveEaseInOut],
animations: {
cell.transform = CGAffineTransform(translationX: 0, y: 0)
})
}
}
/// function for moviing cell up with fade interval
/// expample: let animation = AnimationFactory.makeSlideIn(duration: 0.5, delayFactor: 0.05)
///
/// - Parameters:
/// - rowHeight: CGFloat responsible for the mobing height
/// - duration: TimeInterval responsible for the duration
/// - delayFactor: Double determing the time to start
/// - Returns: return Animation which is typealias which animation need to to create the animation
static func makeMoveUpWithFade(rowHeight: CGFloat, duration: TimeInterval, delayFactor: Double) -> Animation {
return { cell, indexPath, _ in
cell.transform = CGAffineTransform(translationX: 0, y: rowHeight / 2)
cell.alpha = 0
UIView.animate(
withDuration: duration,
delay: delayFactor * Double(indexPath.row),
options: [.curveEaseInOut],
animations: {
cell.transform = CGAffineTransform(translationX: 0, y: 0)
cell.alpha = 1
})
}
}
/// function for moviing cell up with fade interval
/// expample: let animation = AnimationFactory.makeMoveUpWithFade(rowHeight: cell.frame.height, duration: 0.5, delayFactor: 0.05)
///
/// - Parameters:
/// - rowHeight: CGFloat responsible for the mobing height
/// - duration: TimeInterval responsible for the duration
/// - delayFactor: Double determing the time to start
/// - Returns: return Animation which is typealias which animation need to to create the animation
static func makeSlideIn(duration: TimeInterval, delayFactor: Double) -> Animation {
return { cell, indexPath, tableView in
cell.transform = CGAffineTransform(translationX: tableView.bounds.width, y: 0)
UIView.animate(
withDuration: duration,
delay: delayFactor * Double(indexPath.row),
options: [.curveEaseInOut],
animations: {
cell.transform = CGAffineTransform(translationX: 0, y: 0)
})
}
}
}