This repository has been archived by the owner on Mar 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSYTableViewCell.swift
106 lines (91 loc) · 2.72 KB
/
SYTableViewCell.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
//
// SYTableViewCell.swift
// Pods
//
// Created by Shohei Yokoyama on 2016/07/29.
//
//
import UIKit
@IBDesignable
open class SYTableViewCell: UITableViewCell, AnimatableComponent {
public enum AnimationType: Int {
case border, borderWithShadow, background, ripple
}
@IBInspectable open var animationBorderColor = AnimationDefaultColor.border {
didSet {
syLayer.setBorderColor(animationBorderColor)
}
}
@IBInspectable open var animationBackgroundColor = AnimationDefaultColor.background {
didSet {
syLayer.setAnimationBackgroundColor(animationBackgroundColor)
}
}
@IBInspectable open var animationRippleColor = AnimationDefaultColor.ripple {
didSet {
syLayer.setRippleColor(animationRippleColor)
}
}
@IBInspectable open var animationTimingAdapter: Int {
get {
return animationTimingFunction.rawValue
}
set(index) {
animationTimingFunction = SYMediaTimingFunction(rawValue: index) ?? .linear
}
}
@IBInspectable open var animationDuration: CGFloat = 1.5 {
didSet {
syLayer.setAnimationDuration( CFTimeInterval(animationDuration) )
}
}
@IBInspectable open var animationAdapter: Int {
get {
return animationType.rawValue
}
set(index) {
animationType = AnimationType(rawValue: index) ?? .border
}
}
open var isAnimating = false
open var animationTimingFunction: SYMediaTimingFunction = .linear {
didSet {
syLayer.setTimingFunction(animationTimingFunction)
}
}
open var animationType: AnimationType = .border {
didSet {
syLayer.animationType = {
switch animationType {
case .border:
return .border
case .borderWithShadow:
return .borderWithShadow
case .background:
return .background
case .ripple:
return .ripple
}
}()
}
}
fileprivate lazy var syLayer: SYLayer = .init(layer: self.layer)
// MARK: - initializer -
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
}
// MARK: - Public Methods -
open func startAnimating() {
isAnimating = true
syLayer.startAnimating()
}
open func stopAnimating() {
isAnimating = false
syLayer.stopAnimating()
}
// MARK: - Private Methods -
private func configure() {
layer.cornerRadius = 1.1
}
}