|
@@ -17,8 +17,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
private var stuckPointEndTime: CGFloat = 0
|
|
|
// 裁剪开始时间 默认 0
|
|
|
private var cutStartTime: CGFloat = 0
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
// /// 裁剪结束最终的开始时间
|
|
|
// private var cutFinishedStartTime: CGFloat {
|
|
|
// (scrollView.contentOffset.x / perSecondWidth) + (((scrollView.frame.width - videoCropView.frame.width) / 2 + 15) / perSecondWidth) + cutStartTime
|
|
@@ -50,32 +49,32 @@ class PQStuckPointCuttingView: UIView {
|
|
|
/// 频率间隔
|
|
|
private var frequencyMargin: CGFloat = 3
|
|
|
/// 竖线和contentview 父视图的左右间隔
|
|
|
- private var margin: CGFloat = (cScreenWidth - adapterWidth(width: 250)) / 2
|
|
|
-
|
|
|
+ private var margin: CGFloat = (cScreenWidth - adapterWidth(width: 250)) / 2
|
|
|
+
|
|
|
/// 滑动区域大小
|
|
|
private var contentWidth: CGFloat = 0
|
|
|
-
|
|
|
- //竖线一个间隔代表多少 S 是动态的
|
|
|
- private var oneMarginTime:CGFloat = 0
|
|
|
-
|
|
|
- private var isDrawLine:Bool = false
|
|
|
-
|
|
|
- //保存已经绘制的竖线用于变色使用
|
|
|
- var lineLayerArray:Array = Array<CAShapeLayer>.init()
|
|
|
-
|
|
|
- //裁剪区的相素大小
|
|
|
- var cropViewWidth: CGFloat = adapterWidth(width: 250)
|
|
|
+
|
|
|
+ // 竖线一个间隔代表多少 S 是动态的
|
|
|
+ private var oneMarginTime: CGFloat = 0
|
|
|
+
|
|
|
+ private var isDrawLine: Bool = false
|
|
|
+
|
|
|
+ // 保存已经绘制的竖线用于变色使用
|
|
|
+ var lineLayerArray: Array = Array<CAShapeLayer>.init()
|
|
|
+
|
|
|
+ // 裁剪区的相素大小
|
|
|
+ var cropViewWidth: CGFloat = adapterWidth(width: 250)
|
|
|
/// 拖拽改变实时的回调
|
|
|
var videoRangeDidChanged: ((_ startTime: CGFloat, _ endTime: CGFloat) -> Void)?
|
|
|
/// 进度改变实时的回调
|
|
|
var videoProgressDidChanged: ((_ progress: CGFloat) -> Void)?
|
|
|
/// 拖缀结束的回调 type - 1-拖动左边裁剪结束 2--拖动右边裁剪结束 3-进度条拖动结束 4-滑动结束
|
|
|
var videoDidEndDragging: ((_ type: Int, _ startTime: CGFloat, _ endTime: CGFloat, _ progress: CGFloat) -> Void)?
|
|
|
-
|
|
|
- //选择区内的线个数
|
|
|
- var wavSelectCount:Int = 0
|
|
|
- //整首歌的线的个数
|
|
|
- var wavTotalCount:Int = 0
|
|
|
+
|
|
|
+ // 选择区内的线个数
|
|
|
+ var wavSelectCount: Int = 0
|
|
|
+ // 整首歌的线的个数
|
|
|
+ var wavTotalCount: Int = 0
|
|
|
/// 滚动视图
|
|
|
lazy var scrollView: UIScrollView = {
|
|
|
let scrollView = UIScrollView(frame: bounds)
|
|
@@ -92,37 +91,35 @@ class PQStuckPointCuttingView: UIView {
|
|
|
return scrollView
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
//
|
|
|
lazy var rateView: UIView = {
|
|
|
let rateView = UIView(frame: CGRect(x: 0, y: 22, width: scrollView.contentSize.width, height: rateHeight))
|
|
|
rateView.backgroundColor = .clear
|
|
|
return rateView
|
|
|
}()
|
|
|
-
|
|
|
- //总时长
|
|
|
- lazy var tatalTimeLabel:UILabel = {
|
|
|
+
|
|
|
+ // 总时长
|
|
|
+ lazy var tatalTimeLabel: UILabel = {
|
|
|
let tatalTimeLabel = UILabel()
|
|
|
tatalTimeLabel.font = UIFont.systemFont(ofSize: 11)
|
|
|
tatalTimeLabel.textAlignment = .right
|
|
|
tatalTimeLabel.textColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue)
|
|
|
tatalTimeLabel.text = "\(Float64(stuckPointEndTime - stuckPointStartTime).formatDurationToHMS())"
|
|
|
- return tatalTimeLabel
|
|
|
+ return tatalTimeLabel
|
|
|
}()
|
|
|
|
|
|
- //显示选择框
|
|
|
+ // 显示选择框
|
|
|
lazy var videoCropView: UIView = {
|
|
|
-
|
|
|
- let videoCropView:UIView = UIView.init(frame: CGRect(x: (cScreenWidth - cropViewWidth) / 2 , y: 0, width: cropViewWidth, height: 80))
|
|
|
+ let videoCropView: UIView = UIView(frame: CGRect(x: (cScreenWidth - cropViewWidth) / 2, y: 0, width: cropViewWidth, height: 80))
|
|
|
videoCropView.isUserInteractionEnabled = false
|
|
|
videoCropView.layer.borderColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
|
|
|
videoCropView.layer.borderWidth = 2
|
|
|
videoCropView.layer.cornerRadius = 8
|
|
|
-
|
|
|
+
|
|
|
return videoCropView
|
|
|
}()
|
|
|
|
|
|
- override private init(frame: CGRect) {
|
|
|
+ private override init(frame: CGRect) {
|
|
|
super.init(frame: frame)
|
|
|
}
|
|
|
|
|
@@ -136,7 +133,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
if videoDuration < maxCutTime {
|
|
|
maxCutTime = videoDuration
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 更新卡点值
|
|
|
updateEndTime(startTime: startTime, endTime: endTime)
|
|
|
}
|
|
@@ -147,15 +144,15 @@ class PQStuckPointCuttingView: UIView {
|
|
|
func updateEndTime(startTime: CGFloat, endTime: CGFloat) {
|
|
|
stuckPointStartTime = startTime
|
|
|
stuckPointEndTime = endTime
|
|
|
-
|
|
|
+
|
|
|
backgroundColor = PQBFConfig.shared.styleBackGroundColor
|
|
|
addSubview(scrollView)
|
|
|
-
|
|
|
+
|
|
|
addSubview(videoCropView)
|
|
|
videoCropView.addSubview(tatalTimeLabel)
|
|
|
-
|
|
|
+
|
|
|
addData()
|
|
|
-
|
|
|
+
|
|
|
tatalTimeLabel.snp.remakeConstraints { make in
|
|
|
make.width.equalTo(40)
|
|
|
make.height.equalTo(15)
|
|
@@ -163,21 +160,19 @@ class PQStuckPointCuttingView: UIView {
|
|
|
make.right.equalTo(videoCropView.snp_right).offset(-6)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
|
|
|
func addData() {
|
|
|
-
|
|
|
- //1,选择区内的线个数
|
|
|
+ // 1,选择区内的线个数
|
|
|
wavSelectCount = Int(cropViewWidth / (frequencyWidth + frequencyMargin))
|
|
|
- //2,一共绘制的竖线个数
|
|
|
+ // 2,一共绘制的竖线个数
|
|
|
wavTotalCount = Int(videoDuration * CGFloat(wavSelectCount) / CGFloat(stuckPointEndTime - stuckPointStartTime))
|
|
|
-
|
|
|
- //竖线一个间隔代表多少 S 是动态的
|
|
|
+
|
|
|
+ // 竖线一个间隔代表多少 S 是动态的
|
|
|
oneMarginTime = (stuckPointEndTime - stuckPointStartTime) / CGFloat(wavSelectCount)
|
|
|
timeRange = oneMarginTime * 10
|
|
|
- //显示时间 label 的个数 , -1 不够整倍数就不显示时间了
|
|
|
+ // 显示时间 label 的个数 , -1 不够整倍数就不显示时间了
|
|
|
let timeLabelCount = Int(videoDuration / timeRange) - 1
|
|
|
-
|
|
|
+
|
|
|
//
|
|
|
contentWidth = CGFloat(wavTotalCount) * (frequencyWidth + frequencyMargin) + margin * 2 + timeLineWidth / 2
|
|
|
if contentWidth < scrollView.frame.width {
|
|
@@ -193,15 +188,14 @@ class PQStuckPointCuttingView: UIView {
|
|
|
titleLab.textColor = UIColor.hexColor(hexadecimal: "#999999")
|
|
|
titleLab.text = "\((Float64(index) * Float64(timeRange)).formatDurationToHMS())"
|
|
|
scrollView.addSubview(titleLab)
|
|
|
-
|
|
|
}
|
|
|
- if oneMarginTime > 0{
|
|
|
+ if oneMarginTime > 0 {
|
|
|
// 1,处理音频频率
|
|
|
configVoiceFrequency()
|
|
|
// 2,滚动到推荐位置
|
|
|
if scrollView.frame.width < scrollView.contentSize.width {
|
|
|
var offsetX = (stuckPointStartTime / oneMarginTime) * (frequencyWidth + frequencyMargin) + timeLineWidth / 2
|
|
|
-
|
|
|
+
|
|
|
if offsetX < 0 {
|
|
|
offsetX = 0
|
|
|
}
|
|
@@ -211,48 +205,46 @@ class PQStuckPointCuttingView: UIView {
|
|
|
scrollView.contentOffset = CGPoint(x: offsetX, y: 0)
|
|
|
}
|
|
|
scrollView.addSubview(rateView)
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// 处理音频频率
|
|
|
/// - Returns: <#description#>
|
|
|
func configVoiceFrequency() {
|
|
|
-
|
|
|
- //整倍数
|
|
|
+ // 整倍数
|
|
|
let waveTotalCount = Int(wavTotalCount) / cFrequency.count
|
|
|
- //余多少个未画的
|
|
|
+ // 余多少个未画的
|
|
|
var remainder = Int(ceil(CGFloat(wavTotalCount) - CGFloat(waveTotalCount * cFrequency.count)))
|
|
|
var totalWave: [CGFloat] = Array<CGFloat>.init()
|
|
|
- //1,先画整倍数个竖线
|
|
|
+ // 1,先画整倍数个竖线
|
|
|
for _ in 0 ..< waveTotalCount {
|
|
|
totalWave = totalWave + cFrequency
|
|
|
}
|
|
|
if remainder > cFrequency.count - 1 {
|
|
|
remainder = cFrequency.count - 1
|
|
|
}
|
|
|
- //1,再画余数个竖线
|
|
|
+ // 1,再画余数个竖线
|
|
|
if remainder > 0 {
|
|
|
totalWave = totalWave + cFrequency[0 ... remainder]
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
createWave(waveArr: totalWave)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// 更新进度绘制不同色值
|
|
|
/// progress <#progress description#>
|
|
|
func updateProgress(progress: CGFloat) {
|
|
|
-
|
|
|
- for (i,layer) in lineLayerArray.enumerated() {
|
|
|
- if(CGFloat(i) * oneMarginTime <= stuckPointStartTime + progress * CGFloat(stuckPointEndTime - stuckPointStartTime) && CGFloat(i) * oneMarginTime >= stuckPointStartTime){
|
|
|
+ for (i, layer) in lineLayerArray.enumerated() {
|
|
|
+ if CGFloat(i) * oneMarginTime <= stuckPointStartTime + progress * CGFloat(stuckPointEndTime - stuckPointStartTime) && CGFloat(i) * oneMarginTime >= stuckPointStartTime {
|
|
|
BFLog(message: "progress is \(progress) 命中的位置:\(CGFloat(i) * oneMarginTime)")
|
|
|
layer.strokeColor = UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue).cgColor
|
|
|
layer.setNeedsDisplay()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //竖线恢复到原有色值
|
|
|
- func resetDefaultsColor() {
|
|
|
+
|
|
|
+ // 竖线恢复到原有色值
|
|
|
+ func resetDefaultsColor() {
|
|
|
for layer in lineLayerArray {
|
|
|
layer.strokeColor = UIColor.hexColor(hexadecimal: "#999999").cgColor
|
|
|
layer.setNeedsDisplay()
|
|
@@ -276,20 +268,19 @@ class PQStuckPointCuttingView: UIView {
|
|
|
let linePath = UIBezierPath()
|
|
|
// 起点 timeLineWidth / 2 处理显示时间的 label中心为时间点
|
|
|
let originX: CGFloat = CGFloat(Float(i) * Float(frequencyWidth + frequencyMargin)) + margin + timeLineWidth / 2
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
linePath.move(to: CGPoint(x: originX, y: startY))
|
|
|
// 终点
|
|
|
linePath.addLine(to: CGPoint(x: originX, y: endY))
|
|
|
let lineLayer = CAShapeLayer()
|
|
|
-
|
|
|
+
|
|
|
lineLayer.lineWidth = frequencyWidth
|
|
|
lineLayer.strokeColor = UIColor.hexColor(hexadecimal: "#999999").cgColor
|
|
|
lineLayer.path = linePath.cgPath
|
|
|
lineLayer.fillColor = UIColor.black.cgColor
|
|
|
-
|
|
|
- //推荐的开始起点是虚线
|
|
|
- if(oneMarginTime * CGFloat(i) >= stuckPointStartTime && !isDrawLine){
|
|
|
+
|
|
|
+ // 推荐的开始起点是虚线
|
|
|
+ if oneMarginTime * CGFloat(i) >= stuckPointStartTime && !isDrawLine {
|
|
|
isDrawLine = true
|
|
|
linePath.move(to: CGPoint(x: originX, y: -10))
|
|
|
// 终点
|
|
@@ -297,10 +288,8 @@ class PQStuckPointCuttingView: UIView {
|
|
|
lineLayer.path = linePath.cgPath
|
|
|
lineLayer.lineDashPhase = 0
|
|
|
lineLayer.lineDashPattern = [3, 3]
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
lineLayerArray.append(lineLayer)
|
|
|
rateView.layer.insertSublayer(lineLayer, at: 0)
|
|
|
}
|
|
@@ -315,14 +304,13 @@ class PQStuckPointCuttingView: UIView {
|
|
|
|
|
|
/// scrollView滑动代理
|
|
|
extension PQStuckPointCuttingView: UIScrollViewDelegate {
|
|
|
- func scrollViewDidScroll(_: UIScrollView) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ func scrollViewDidScroll(_: UIScrollView) {}
|
|
|
+
|
|
|
func scrollViewDidEndDecelerating(_: UIScrollView) {
|
|
|
BFLog(message: "拖拽结束 - 回调")
|
|
|
resetDefaultsColor()
|
|
|
}
|
|
|
+
|
|
|
func scrollViewDidEndScrollingAnimation(_: UIScrollView) {
|
|
|
BFLog(message: "scrollViewDidEndScrollingAnimation")
|
|
|
resetDefaultsColor()
|