-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationPartaCarView.swift
240 lines (207 loc) · 10.7 KB
/
AnimationPartaCarView.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//
// AnimationPartaCarView.swift
// Generated by Core Animator version 1.3.1 on 24/02/2016.
//
// DO NOT MODIFY THIS FILE. IT IS AUTO-GENERATED AND WILL BE OVERWRITTEN
//
import UIKit
@IBDesignable
class AnimationPartaCarView : {
var animationCompletions = Dictionary<CAAnimation, (Bool) -> Void>()
var viewsByName: [String : UIView]!
// - MARK: Life Cycle
convenience init() {
self.init(frame: CGRect(x: 0, y: 0, width: 1080, height: 1920))
}
override init(frame: CGRect) {
super.init(frame: frame)
self.setupHierarchy()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupHierarchy()
}
// - MARK: Scaling
override func layoutSubviews() {
super.layoutSubviews()
if let scalingView = self.viewsByName["__scaling__"] {
var xScale = self.bounds.size.width / scalingView.bounds.size.width
var yScale = self.bounds.size.height / scalingView.bounds.size.height
switch contentMode {
case .ScaleToFill:
break
case .ScaleAspectFill:
let scale = max(xScale, yScale)
xScale = scale
yScale = scale
default:
let scale = min(xScale, yScale)
xScale = scale
yScale = scale
}
scalingView.transform = CGAffineTransformMakeScale(xScale, yScale)
scalingView.center = CGPoint(x:CGRectGetMidX(self.bounds), y:CGRectGetMidY(self.bounds))
}
}
// - MARK: Setup
func setupHierarchy() {
var viewsByName: [String : UIView] = [:]
let bundle = NSBundle(forClass:self.dynamicType)
let __scaling__ = UIView()
__scaling__.bounds = CGRect(x:0, y:0, width:1080, height:1920)
__scaling__.center = CGPoint(x:540.0, y:960.0)
self.addSubview(__scaling__)
viewsByName["__scaling__"] = __scaling__
let logolaunch = UIImageView()
logolaunch.bounds = CGRect(x:0, y:0, width:347.0, height:347.0)
logolaunch.layer.anchorPoint = CGPoint(x:0.506, y:0.508)
var imgLogolaunch: UIImage!
if let imagePath = bundle.pathForResource("logolaunch.png", ofType:nil) {
imgLogolaunch = UIImage(contentsOfFile:imagePath)
}else {
print("** Warning: Could not create image from 'logolaunch.png'. Please make sure that it is added to the project directly (not in a folder reference).")
}
logolaunch.image = imgLogolaunch
logolaunch.contentMode = .Center
logolaunch.layer.position = CGPoint(x:542.023, y:518.711)
__scaling__.addSubview(logolaunch)
viewsByName["logolaunch"] = logolaunch
let buttonInscri = UIImageView()
buttonInscri.bounds = CGRect(x:0, y:0, width:450.0, height:200.0)
var imgButtonInscri: UIImage!
if let imagePath = bundle.pathForResource("buttonInscri.png", ofType:nil) {
imgButtonInscri = UIImage(contentsOfFile:imagePath)
}else {
print("** Warning: Could not create image from 'buttonInscri.png'. Please make sure that it is added to the project directly (not in a folder reference).")
}
buttonInscri.image = imgButtonInscri
buttonInscri.contentMode = .Center
buttonInscri.layer.position = CGPoint(x:540.000, y:1359.738)
buttonInscri.transform = CGAffineTransformMakeScale(0.67, 0.67)
__scaling__.addSubview(buttonInscri)
viewsByName["buttonInscri"] = buttonInscri
let buttonCo2 = UIImageView()
buttonCo2.bounds = CGRect(x:0, y:0, width:625.0, height:277.0)
var imgButtonCo2: UIImage!
if let imagePath = bundle.pathForResource("buttonCo2.png", ofType:nil) {
imgButtonCo2 = UIImage(contentsOfFile:imagePath)
}else {
print("** Warning: Could not create image from 'buttonCo2.png'. Please make sure that it is added to the project directly (not in a folder reference).")
}
buttonCo2.image = imgButtonCo2
buttonCo2.contentMode = .Center
buttonCo2.layer.position = CGPoint(x:540.000, y:1175.462)
buttonCo2.transform = CGAffineTransformMakeScale(0.49, 0.47)
__scaling__.addSubview(buttonCo2)
viewsByName["buttonCo2"] = buttonCo2
self.viewsByName = viewsByName
}
// - MARK: mouvement
func addMouvementAnimation() {
addMouvementAnimationWithBeginTime(0, fillMode: kCAFillModeBoth, removedOnCompletion: false, completion: nil)
}
func addMouvementAnimation(completion: ((Bool) -> Void)?) {
addMouvementAnimationWithBeginTime(0, fillMode: kCAFillModeBoth, removedOnCompletion: false, completion: completion)
}
func addMouvementAnimation(removedOnCompletion removedOnCompletion: Bool) {
addMouvementAnimationWithBeginTime(0, fillMode: removedOnCompletion ? kCAFillModeRemoved : kCAFillModeBoth, removedOnCompletion: removedOnCompletion, completion: nil)
}
func addMouvementAnimation(removedOnCompletion removedOnCompletion: Bool, completion: ((Bool) -> Void)?) {
addMouvementAnimationWithBeginTime(0, fillMode: removedOnCompletion ? kCAFillModeRemoved : kCAFillModeBoth, removedOnCompletion: removedOnCompletion, completion: completion)
}
func addMouvementAnimationWithBeginTime(beginTime: CFTimeInterval, fillMode: String, removedOnCompletion: Bool, completion: ((Bool) -> Void)?) {
let linearTiming = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
if let complete = completion {
let representativeAnimation = CABasicAnimation(keyPath: "not.a.real.key")
representativeAnimation.duration = 0.500
representativeAnimation.delegate = self
self.layer.addAnimation(representativeAnimation, forKey: "Mouvement")
self.animationCompletions[layer.animationForKey("Mouvement")!] = complete
}
let logolaunchOpacityAnimation = CAKeyframeAnimation(keyPath: "opacity")
logolaunchOpacityAnimation.duration = 0.500
logolaunchOpacityAnimation.values = [0.000 as Float, 1.000 as Float]
logolaunchOpacityAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
logolaunchOpacityAnimation.timingFunctions = [linearTiming]
logolaunchOpacityAnimation.beginTime = beginTime
logolaunchOpacityAnimation.fillMode = fillMode
logolaunchOpacityAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["logolaunch"]?.layer.addAnimation(logolaunchOpacityAnimation, forKey:"mouvement_Opacity")
let logolaunchTranslationXAnimation = CAKeyframeAnimation(keyPath: "transform.translation.x")
logolaunchTranslationXAnimation.duration = 0.500
logolaunchTranslationXAnimation.values = [-300.000 as Float, -4.609 as Float]
logolaunchTranslationXAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
logolaunchTranslationXAnimation.timingFunctions = [linearTiming]
logolaunchTranslationXAnimation.beginTime = beginTime
logolaunchTranslationXAnimation.fillMode = fillMode
logolaunchTranslationXAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["logolaunch"]?.layer.addAnimation(logolaunchTranslationXAnimation, forKey:"mouvement_TranslationX")
let buttonCo2OpacityAnimation = CAKeyframeAnimation(keyPath: "opacity")
buttonCo2OpacityAnimation.duration = 0.500
buttonCo2OpacityAnimation.values = [0.000 as Float, 1.000 as Float]
buttonCo2OpacityAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
buttonCo2OpacityAnimation.timingFunctions = [linearTiming]
buttonCo2OpacityAnimation.beginTime = beginTime
buttonCo2OpacityAnimation.fillMode = fillMode
buttonCo2OpacityAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["buttonCo2"]?.layer.addAnimation(buttonCo2OpacityAnimation, forKey:"mouvement_Opacity")
let buttonCo2TranslationXAnimation = CAKeyframeAnimation(keyPath: "transform.translation.x")
buttonCo2TranslationXAnimation.duration = 0.500
buttonCo2TranslationXAnimation.values = [-300.000 as Float, 0.000 as Float]
buttonCo2TranslationXAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
buttonCo2TranslationXAnimation.timingFunctions = [linearTiming]
buttonCo2TranslationXAnimation.beginTime = beginTime
buttonCo2TranslationXAnimation.fillMode = fillMode
buttonCo2TranslationXAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["buttonCo2"]?.layer.addAnimation(buttonCo2TranslationXAnimation, forKey:"mouvement_TranslationX")
let buttonInscriOpacityAnimation = CAKeyframeAnimation(keyPath: "opacity")
buttonInscriOpacityAnimation.duration = 0.500
buttonInscriOpacityAnimation.values = [0.000 as Float, 1.000 as Float]
buttonInscriOpacityAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
buttonInscriOpacityAnimation.timingFunctions = [linearTiming]
buttonInscriOpacityAnimation.beginTime = beginTime
buttonInscriOpacityAnimation.fillMode = fillMode
buttonInscriOpacityAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["buttonInscri"]?.layer.addAnimation(buttonInscriOpacityAnimation, forKey:"mouvement_Opacity")
let buttonInscriTranslationXAnimation = CAKeyframeAnimation(keyPath: "transform.translation.x")
buttonInscriTranslationXAnimation.duration = 0.500
buttonInscriTranslationXAnimation.values = [-300.000 as Float, 0.000 as Float]
buttonInscriTranslationXAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
buttonInscriTranslationXAnimation.timingFunctions = [linearTiming]
buttonInscriTranslationXAnimation.beginTime = beginTime
buttonInscriTranslationXAnimation.fillMode = fillMode
buttonInscriTranslationXAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["buttonInscri"]?.layer.addAnimation(buttonInscriTranslationXAnimation, forKey:"mouvement_TranslationX")
let buttonInscriTranslationYAnimation = CAKeyframeAnimation(keyPath: "transform.translation.y")
buttonInscriTranslationYAnimation.duration = 0.500
buttonInscriTranslationYAnimation.values = [0.000 as Float, 0.000 as Float]
buttonInscriTranslationYAnimation.keyTimes = [0.000 as Float, 1.000 as Float]
buttonInscriTranslationYAnimation.timingFunctions = [linearTiming]
buttonInscriTranslationYAnimation.beginTime = beginTime
buttonInscriTranslationYAnimation.fillMode = fillMode
buttonInscriTranslationYAnimation.removedOnCompletion = removedOnCompletion
self.viewsByName["buttonInscri"]?.layer.addAnimation(buttonInscriTranslationYAnimation, forKey:"mouvement_TranslationY")
}
func removeMouvementAnimation() {
self.layer.removeAnimationForKey("Mouvement")
self.viewsByName["logolaunch"]?.layer.removeAnimationForKey("mouvement_Opacity")
self.viewsByName["logolaunch"]?.layer.removeAnimationForKey("mouvement_TranslationX")
self.viewsByName["buttonCo2"]?.layer.removeAnimationForKey("mouvement_Opacity")
self.viewsByName["buttonCo2"]?.layer.removeAnimationForKey("mouvement_TranslationX")
self.viewsByName["buttonInscri"]?.layer.removeAnimationForKey("mouvement_Opacity")
self.viewsByName["buttonInscri"]?.layer.removeAnimationForKey("mouvement_TranslationX")
self.viewsByName["buttonInscri"]?.layer.removeAnimationForKey("mouvement_TranslationY")
}
override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let completion = self.animationCompletions[anim] {
self.animationCompletions.removeValueForKey(anim)
completion(flag)
}
}
func removeAllAnimations() {
for subview in viewsByName.values {
subview.layer.removeAllAnimations()
}
self.layer.removeAnimationForKey("Mouvement")
}
}