-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathVideoTrimmerThumb.swift
119 lines (86 loc) · 3.34 KB
/
VideoTrimmerThumb.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
107
108
109
110
111
112
113
114
115
116
117
118
//
// VideoTrimmerThumb.swift
// VideoTrimmer
//
// Created by Andreas Verhoeven on 02/09/2020.
// Copyright © 2020 Andreas Verhoeven. All rights reserved.
//
import UIKit
class VideoTrimmerThumb: UIView {
var isActive = false
var leadingChevronImageView = UIImageView(image: UIImage(systemName: "chevron.compact.left"))
var trailingChevronView = UIImageView(image: UIImage(systemName: "chevron.compact.right"))
var wrapperView = UIView()
var leadingView = UIView()
var trailingView = UIView()
var topView = UIView()
var bottomView = UIView()
let leadingGrabber = UIControl()
let trailingGrabber = UIControl()
let chevronWidth = CGFloat(16)
let edgeHeight = CGFloat(4)
// MARK: - Input
@objc private func x(_ sender: Any) {
}
// MARK: - Private
private func updateColor() {
let color = UIColor.systemYellow
leadingView.backgroundColor = color
trailingView.backgroundColor = color
topView.backgroundColor = color
bottomView.backgroundColor = color
}
private func setup() {
leadingChevronImageView.contentMode = .scaleAspectFill
trailingChevronView.contentMode = .scaleAspectFill
leadingChevronImageView.tintColor = .white
trailingChevronView.tintColor = .white
leadingChevronImageView.tintAdjustmentMode = .normal
trailingChevronView.tintAdjustmentMode = .normal
leadingView.layer.cornerRadius = 6
leadingView.layer.cornerCurve = .continuous
leadingView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMinXMinYCorner]
trailingView.layer.cornerRadius = 6
trailingView.layer.cornerCurve = .continuous
trailingView.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMaxXMinYCorner]
leadingView.addSubview(leadingChevronImageView)
trailingView.addSubview(trailingChevronView)
// wrapperView.layer.shadowColor = UIColor.black.cgColor
// wrapperView.layer.shadowOffset = .zero
// wrapperView.layer.shadowRadius = 2
// wrapperView.layer.shadowOpacity = 0.25
wrapperView.addSubview(leadingView)
wrapperView.addSubview(trailingView)
wrapperView.addSubview(topView)
wrapperView.addSubview(bottomView)
addSubview(wrapperView)
wrapperView.addSubview(leadingGrabber)
wrapperView.addSubview(trailingGrabber)
updateColor()
}
// MARK: - UIView
override func layoutSubviews() {
super.layoutSubviews()
let size = bounds.size
wrapperView.frame = CGRect(origin: .zero, size: size)
leadingView.frame = CGRect(x: 0, y: 0, width: chevronWidth, height: bounds.height)
trailingView.frame = CGRect(x: bounds.width - chevronWidth, y: 0, width: chevronWidth, height: bounds.height)
topView.frame = CGRect(x: chevronWidth, y: 0, width: bounds.width - chevronWidth * 2, height: edgeHeight)
bottomView.frame = CGRect(x: chevronWidth, y: bounds.height - edgeHeight, width: bounds.width - chevronWidth * 2, height: edgeHeight)
let chevronHorizontalInset = CGFloat(2)
let chevronVerticalInset = CGFloat(8)
let chevronFrame = CGRect(x: chevronHorizontalInset, y: chevronVerticalInset, width: chevronWidth - chevronHorizontalInset * 2, height: size.height - chevronVerticalInset * 2)
leadingChevronImageView.frame = chevronFrame
trailingChevronView.frame = chevronFrame
leadingGrabber.frame = leadingView.frame
trailingGrabber.frame = trailingView.frame
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
}
}