-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathContents.swift
50 lines (40 loc) · 1.45 KB
/
Contents.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
import UIKit
import PlaygroundSupport
let liveViewFrame = CGRect(x: 0, y: 0, width: 500, height: 500)
let liveView = UIView(frame: liveViewFrame)
liveView.backgroundColor = .white
PlaygroundPage.current.liveView = liveView
let smallFrame = CGRect(x: 0, y: 0, width: 100, height: 100)
let square = UIView(frame: smallFrame)
square.backgroundColor = .purple
liveView.addSubview(square)
/*
UIView.animate(withDuration: 3.0, animations: {
square.backgroundColor = .orange
square.frame = CGRect(x: 150, y: 150, width: 200, height:
200)
}, completion: { (_) in
UIView.animate(withDuration: 3.0, animations: {
square.backgroundColor = .purple
square.frame = smallFrame
})
})
*/
/*
UIView.animate(withDuration: 3.0, delay: 2.0, options: [.repeat], animations: {
square.backgroundColor = .orange
square.frame = CGRect(x: 400, y: 400, width: 100, height: 100)
}, completion: nil)
*/
UIView.animate(withDuration: 2.0, animations: {
square.backgroundColor = .orange
let scaleTransform = CGAffineTransform(scaleX: 2.0, y: 2.0)
let rotateTransform = CGAffineTransform(rotationAngle: .pi)
let translateTransform = CGAffineTransform(translationX: 200, y: 200)
let comboTransform = scaleTransform.concatenating(rotateTransform).concatenating(translateTransform)
square.transform = comboTransform
}) { (_) in
UIView.animate(withDuration: 2.0, animations: {
square.transform = CGAffineTransform.identity
})
}