-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIButton+Rotation.swift
More file actions
38 lines (32 loc) · 1.1 KB
/
UIButton+Rotation.swift
File metadata and controls
38 lines (32 loc) · 1.1 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
// RotatingButton
// Created by Daniel Budyński 👾
// https://github.com/Budyn/
// MacOS 10.13, Swift 4.0
import UIKit
extension UIButton {
func rotate(time: Double = 0.7) {
UIView.animateKeyframes(withDuration: time,
delay: 0.0,
options: [],
animations: {
self.prepareAnimation()
}, completion: { _ in
self.finishAnimation()
})
}
private func prepareAnimation() {
UIView.addKeyframe(withRelativeStartTime: 0,
relativeDuration: 0.5,
animations: {
self.transform = CGAffineTransform(rotationAngle: -.pi)
})
UIView.addKeyframe(withRelativeStartTime: 0.5,
relativeDuration: 0.5,
animations: {
self.transform = CGAffineTransform(rotationAngle: -.pi * 2)
})
}
private func finishAnimation() {
self.transform = .identity
}
}