|
@@ -70,6 +70,8 @@ class PQStuckPointCuttingView: UIView {
|
|
|
var videoProgressDidChanged: ((_ progress: CGFloat) -> Void)?
|
|
|
|
|
|
var videoDidEndDragging: ((_ type: Int, _ startTime: CGFloat, _ endTime: CGFloat, _ progress: CGFloat) -> Void)?
|
|
|
+
|
|
|
+ var videoDidBeginDrag: (() -> Void)?
|
|
|
|
|
|
|
|
|
var wavSelectCount: Int = 0
|
|
@@ -187,16 +189,16 @@ class PQStuckPointCuttingView: UIView {
|
|
|
func addData() {
|
|
|
|
|
|
wavSelectCount = Int(cropViewWidth / (frequencyWidth + frequencyMargin))
|
|
|
-
|
|
|
- wavTotalCount = Int(videoDuration * CGFloat(wavSelectCount) / CGFloat(stuckPointEndTime - stuckPointStartTime))
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
oneMarginTime = (stuckPointEndTime - stuckPointStartTime) / CGFloat(wavSelectCount)
|
|
|
+
|
|
|
+
|
|
|
+ wavTotalCount = Int(videoDuration / oneMarginTime)
|
|
|
+
|
|
|
timeRange = oneMarginTime * 10
|
|
|
|
|
|
- let timeLabelCount = Int(videoDuration / timeRange) - 1
|
|
|
-
|
|
|
-
|
|
|
+ let timeLabelCount = Int(wavTotalCount / 10)
|
|
|
contentWidth = CGFloat(wavTotalCount) * (frequencyWidth + frequencyMargin) + margin * 2 + timeLineWidth / 2
|
|
|
if contentWidth < scrollView.frame.width {
|
|
|
contentWidth = scrollView.frame.width
|
|
@@ -206,7 +208,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
|
|
|
for index in 0 ... timeLabelCount {
|
|
|
scrollView.viewWithTag(100 + index)?.removeFromSuperview()
|
|
|
- let titleLab = UILabel(frame: CGRect(x: CGFloat(index) * (timeLineWidth + timeLineMargin) + margin, y: rateView.frame.maxY, width: timeLineWidth, height: 30))
|
|
|
+ let titleLab = UILabel(frame: CGRect(x: CGFloat(index) * (frequencyWidth + frequencyMargin) * 10 + margin - timeLineWidth / 2, y: rateView.frame.maxY, width: timeLineWidth, height: 30))
|
|
|
titleLab.font = UIFont.systemFont(ofSize: 11)
|
|
|
titleLab.textAlignment = .center
|
|
|
titleLab.numberOfLines = 1
|
|
@@ -324,7 +326,7 @@ class PQStuckPointCuttingView: UIView {
|
|
|
let lastLine:UIView = scrollView.viewWithTag(100 + Int(videoDuration / timeRange) - 1) ?? UIView.init()
|
|
|
|
|
|
let startTime = videoDuration / lastLine.frame.maxX * scrollView.contentOffset.x
|
|
|
- BFLog(message: "拖拽结束 - 回调\(scrollView.contentOffset) \(scrollView.contentSize) 开始时间为:\(startTime)")
|
|
|
+ BFLog(message: "拖拽结束 - 回调\(scrollView.contentOffset) \(scrollView.contentSize) 开始时间为:\(startTime) 结束时间为:\(startTime + CGFloat(stuckPointEndTime - stuckPointStartTime))")
|
|
|
if(videoDidEndDragging != nil){
|
|
|
videoDidEndDragging!(1,startTime,startTime + CGFloat(stuckPointEndTime - stuckPointStartTime),0)
|
|
|
}
|
|
@@ -342,17 +344,30 @@ class PQStuckPointCuttingView: UIView {
|
|
|
|
|
|
extension PQStuckPointCuttingView: UIScrollViewDelegate {
|
|
|
func scrollViewDidScroll(_: UIScrollView) {}
|
|
|
-
|
|
|
+
|
|
|
+ func scrollViewWillBeginDragging(_ :UIScrollView){
|
|
|
+ if(videoDidBeginDrag != nil){
|
|
|
+ videoDidBeginDrag!()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
func scrollViewDidEndDecelerating(_: UIScrollView) {
|
|
|
- moveEnd()
|
|
|
+ if !scrollView.isDragging, !scrollView.isDecelerating {
|
|
|
+ moveEnd()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- func scrollViewDidEndDragging(_:UIScrollView,willDecelerate:Bool){
|
|
|
- moveEnd()
|
|
|
+ func scrollViewDidEndDragging(_:UIScrollView,willDecelerate decelerate:Bool){
|
|
|
+ if !decelerate, !scrollView.isDragging, !scrollView.isDecelerating {
|
|
|
+ moveEnd()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func scrollViewDidEndScrollingAnimation(_: UIScrollView) {
|
|
|
BFLog(message: "scrollViewDidEndScrollingAnimation")
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|