-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewController.swift
69 lines (59 loc) · 1.98 KB
/
ViewController.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
//
// ViewController.swift
// Animation
//
// Created by Julian Moorhouse on 10/08/2019.
// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var imageView: UIImageView!
var currentAnimation = 0
override func viewDidLoad() {
super.viewDidLoad()
imageView = UIImageView(image: UIImage(named: "penguin"))
imageView.center = CGPoint(x: 512, y: 384)
view.addSubview(imageView)
}
@IBAction func tap(_ sender: UIButton) {
sender.isHidden = true
// UIView.animate(withDuration: 1, delay: 0, options: [], animations: {
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: [], animations: {
switch self.currentAnimation {
case 0:
self.imageView.transform = CGAffineTransform(scaleX: 2, y: 2)
break
case 1:
self.imageView.transform = .identity
case 2:
self.imageView.transform = CGAffineTransform(translationX: -256, y: -256)
break
case 3:
self.imageView.transform = .identity
break
case 4:
self.imageView.transform = CGAffineTransform(rotationAngle: .pi)
break
case 5:
self.imageView.transform = .identity
break
case 6:
self.imageView.alpha = 0.1
self.imageView.backgroundColor = .green
break
case 7:
self.imageView.alpha = 1
self.imageView.backgroundColor = .clear
break
default:
break
}
}) { finished in
sender.isHidden = false
}
currentAnimation += 1
if currentAnimation > 7 {
currentAnimation = 0
}
}
}