forked from SteveBarnegren/TweenKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasingExampleCell.swift
More file actions
66 lines (49 loc) · 1.64 KB
/
Copy pathEasingExampleCell.swift
File metadata and controls
66 lines (49 loc) · 1.64 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
//
// EasingExampleCell.swift
// Example
//
// Created by Steven Barnegren on 27/03/2017.
// Copyright © 2017 Steve Barnegren. All rights reserved.
//
import UIKit
class EasingExampleCell: UITableViewCell {
// MARK: - Internal
func setTitle(title: String) {
self.titleLabel.text = title
}
var animatedPct = 0.0 {
didSet{
setNeedsLayout()
layoutIfNeeded()
}
}
// MARK: - Outlets
@IBOutlet weak private var easingContainerView: UIView!
@IBOutlet weak private var titleLabel: UILabel!
// MARK: - Properties
private let squareLayer: CALayer = {
let layer = CALayer()
layer.backgroundColor = UIColor.blue.cgColor
return layer
}()
// MARK: - UITableViewCell
override func awakeFromNib() {
super.awakeFromNib()
easingContainerView.layer.addSublayer(squareLayer)
}
override func layoutSubviews() {
super.layoutSubviews()
CATransaction.begin()
CATransaction.setDisableActions(true)
let sideLength = Swift.min(easingContainerView.bounds.size.width,
easingContainerView.bounds.size.height)
let min = CGFloat(0.0)
let max = easingContainerView.bounds.size.width - sideLength
let x = min + ((max - min) * CGFloat(animatedPct))
squareLayer.frame = CGRect(x: x,
y: 0,
width: sideLength,
height: sideLength)
CATransaction.commit()
}
}