|
@@ -1,450 +0,0 @@
|
|
|
-//
|
|
|
-// PublishVideoView.swift
|
|
|
-// RainbowPlanet
|
|
|
-//
|
|
|
-// Created by Christopher on 2019/6/19.
|
|
|
-// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
-//
|
|
|
-
|
|
|
-import UIKit
|
|
|
-import RxSwift
|
|
|
-import RxCocoa
|
|
|
-import JXSegmentedView
|
|
|
-
|
|
|
-enum BtnActionType {
|
|
|
- case back // 返回
|
|
|
- case reverse // 翻转
|
|
|
- case music // 音乐
|
|
|
- case filter // 滤镜
|
|
|
- case delete // 回删
|
|
|
- case confirm // 确定
|
|
|
-}
|
|
|
-
|
|
|
-class PublishVideoView: BaseView {
|
|
|
-
|
|
|
- typealias BtnClickClosure = (_ btnType: BtnActionType) -> Void
|
|
|
- var btnClickClosure : BtnClickClosure?
|
|
|
-
|
|
|
- typealias VideoClosure = (_ isRecord: Int) -> Void
|
|
|
- var videoClosure : VideoClosure?
|
|
|
-
|
|
|
- var maxDuration: CGFloat? {
|
|
|
- didSet {
|
|
|
- progressView.maxDuration = maxDuration!
|
|
|
- }
|
|
|
- }
|
|
|
- var minDuration: CGFloat? {
|
|
|
- didSet {
|
|
|
- progressView.minDuration = minDuration!
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 是否正在录制
|
|
|
- @objc var recording: Bool = false
|
|
|
-
|
|
|
- override func setupViews() {
|
|
|
- self.backgroundColor = kffffffColor
|
|
|
-
|
|
|
- addSubview(progressView)
|
|
|
- addSubview(backButton)
|
|
|
- addSubview(recordButton)
|
|
|
- addSubview(segmentedView)
|
|
|
-
|
|
|
- addSubview(controlBackView)
|
|
|
- controlBackView.addSubview(reverseButton)
|
|
|
- controlBackView.addSubview(musicButton)
|
|
|
- controlBackView.addSubview(filterButton)
|
|
|
-
|
|
|
- addSubview(timeBackView)
|
|
|
- timeBackView.addSubview(timeDotView)
|
|
|
- timeBackView.addSubview(timeLabel)
|
|
|
-
|
|
|
- addSubview(selBackView)
|
|
|
- selBackView.addSubview(confirmButton)
|
|
|
- selBackView.addSubview(delButton)
|
|
|
-
|
|
|
- addSubview(previewView)
|
|
|
- insertSubview(previewView, at: 0)
|
|
|
- }
|
|
|
-
|
|
|
- override func setupLayouts() {
|
|
|
-
|
|
|
- backButton.snp.makeConstraints { (make) in
|
|
|
- make.top.equalTo(55)
|
|
|
- make.left.equalTo(5)
|
|
|
- make.width.equalTo(40)
|
|
|
- make.height.equalTo(40)
|
|
|
- }
|
|
|
-
|
|
|
- recordButton.snp.makeConstraints { (make) in
|
|
|
- make.bottom.equalTo(-56)
|
|
|
- make.centerX.equalToSuperview()
|
|
|
- make.width.equalTo(100)
|
|
|
- make.height.equalTo(100)
|
|
|
- }
|
|
|
-
|
|
|
- segmentedView.snp.makeConstraints { (make) in
|
|
|
- make.height.equalTo(40)
|
|
|
- make.left.equalTo(14)
|
|
|
- make.right.equalTo(-14)
|
|
|
- make.bottom.equalTo(recordButton.snp.top).offset(-21)
|
|
|
- }
|
|
|
-
|
|
|
- /***** 翻转、音乐、滤镜 *****/
|
|
|
- controlBackView.snp.makeConstraints { (make) in
|
|
|
- make.top.equalTo(64)
|
|
|
- make.right.equalTo(-15)
|
|
|
- make.width.equalTo(44)
|
|
|
- }
|
|
|
-
|
|
|
- reverseButton.snp.makeConstraints { (make) in
|
|
|
- make.top.left.right.equalToSuperview()
|
|
|
- make.height.equalTo(46)
|
|
|
- }
|
|
|
- reverseButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
|
|
|
-
|
|
|
- musicButton.snp.makeConstraints { (make) in
|
|
|
- make.top.equalTo(reverseButton.snp.bottom).offset(20)
|
|
|
- make.left.right.equalToSuperview()
|
|
|
- make.height.equalTo(46)
|
|
|
- }
|
|
|
- musicButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
|
|
|
-
|
|
|
- filterButton.snp.makeConstraints { (make) in
|
|
|
- make.top.equalTo(musicButton.snp.bottom).offset(20)
|
|
|
- make.left.right.equalToSuperview()
|
|
|
- make.height.equalTo(46)
|
|
|
- make.bottom.equalToSuperview()
|
|
|
- }
|
|
|
- filterButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
|
|
|
-
|
|
|
- /***** 拍摄时长 *****/
|
|
|
- timeBackView.snp.makeConstraints { (make) in
|
|
|
- make.bottom.equalTo(recordButton.snp.top).offset(-20)
|
|
|
- make.centerX.equalToSuperview()
|
|
|
- make.height.equalTo(20)
|
|
|
- }
|
|
|
-
|
|
|
- timeDotView.snp.makeConstraints { (make) in
|
|
|
- make.left.equalToSuperview()
|
|
|
- make.centerY.equalToSuperview()
|
|
|
- make.size.equalTo(8)
|
|
|
- }
|
|
|
-
|
|
|
- timeLabel.snp.makeConstraints { (make) in
|
|
|
- make.left.equalTo(timeDotView.snp.right).offset(4)
|
|
|
- make.top.bottom.equalToSuperview()
|
|
|
- make.width.equalTo(40)
|
|
|
- make.right.equalToSuperview()
|
|
|
- }
|
|
|
-
|
|
|
- /***** 回删、确定 *****/
|
|
|
- selBackView.snp.makeConstraints { (make) in
|
|
|
- make.bottom.equalTo(-83)
|
|
|
- make.right.equalTo(-24*kScaleWidth)
|
|
|
- make.height.equalTo(50)
|
|
|
- }
|
|
|
-
|
|
|
- confirmButton.snp.makeConstraints { (make) in
|
|
|
- make.top.bottom.right.equalToSuperview()
|
|
|
- make.width.equalTo(30)
|
|
|
- }
|
|
|
- confirmButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
|
|
|
-
|
|
|
- delButton.snp.makeConstraints { (make) in
|
|
|
- make.right.equalTo(confirmButton.snp.left).offset(-30*kScaleWidth)
|
|
|
- make.top.bottom.equalToSuperview()
|
|
|
- make.width.equalTo(30)
|
|
|
- make.left.equalToSuperview()
|
|
|
- }
|
|
|
- delButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
|
|
|
-
|
|
|
- /***** 预览视图 *****/
|
|
|
- previewView.snp.makeConstraints { (make) in
|
|
|
- make.edges.equalToSuperview()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // MARK: - 创建视图控件
|
|
|
- //1.初始化JXSegmentedViewx
|
|
|
- lazy var segmentedView: JXSegmentedView = {
|
|
|
- let segmentedView = JXSegmentedView()
|
|
|
- segmentedView.delegate = self
|
|
|
- segmentedView.dataSource = segmentedDataSource
|
|
|
- segmentedView.selectItemAt(index: 2)
|
|
|
- segmentedView.defaultSelectedIndex = 2
|
|
|
- segmentedView.backgroundColor = kRGBAColor(r: 0, g: 0, b: 0, a: 0.2)
|
|
|
- segmentedView.cornerRadius = 20
|
|
|
- segmentedView.masksToBounds = true
|
|
|
- return segmentedView
|
|
|
- }()
|
|
|
-
|
|
|
- //2.初始化dataSource
|
|
|
- private lazy var segmentedDataSource: JXSegmentedTitleDataSource = {
|
|
|
- let segmentedDataSource = JXSegmentedTitleDataSource()
|
|
|
- segmentedDataSource.isTitleColorGradientEnabled = true
|
|
|
- segmentedDataSource.isItemSpacingAverageEnabled = true
|
|
|
- segmentedDataSource.isTitleZoomEnabled = true
|
|
|
- segmentedDataSource.titleNormalColor = kffffffColor
|
|
|
- segmentedDataSource.titleSelectedColor = k333333Color
|
|
|
- segmentedDataSource.titleNormalFont = kRegularFont14!
|
|
|
- segmentedDataSource.titleSelectedFont = kBoldFont22
|
|
|
- segmentedDataSource.titles = ["极慢","慢","标准","快","极快"]
|
|
|
- //reloadData(selectedIndex:)方法一定要调用,方法内部会刷新数据源数组
|
|
|
- segmentedDataSource.reloadData(selectedIndex: 2)
|
|
|
-
|
|
|
- return segmentedDataSource
|
|
|
- }()
|
|
|
-
|
|
|
- //3.初始化指示器indicator
|
|
|
- private lazy var indicator: JXSegmentedIndicatorBackgroundView = {
|
|
|
- let indicator = JXSegmentedIndicatorBackgroundView()
|
|
|
-// indicator.indicatorColors = [k62CC74Color,.white,.white]
|
|
|
- indicator.indicatorHeight = 40
|
|
|
- return indicator
|
|
|
- }()
|
|
|
-
|
|
|
- lazy var backButton: UIButton = {
|
|
|
- let backButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- backButton.setImage(kImage(name: "video_btn_close_white"), for: UIControl.State.normal)
|
|
|
- backButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- if let btnClickClosure = self?.btnClickClosure {
|
|
|
- btnClickClosure(BtnActionType.back)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
- return backButton
|
|
|
- }()
|
|
|
-
|
|
|
- // MARK:放置"翻转、音乐、滤镜"のView
|
|
|
- lazy var controlBackView: UIView = {
|
|
|
- let controlBackView = UIView()
|
|
|
- return controlBackView
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var reverseButton: UIButton = {
|
|
|
- let reverseButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- reverseButton.setImage(kImage(name: "video_ico_overturn"), for: UIControl.State.normal)
|
|
|
- reverseButton.setTitle("翻转", for: UIControl.State.normal)
|
|
|
- reverseButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
- reverseButton.titleLabel?.font = kRegularFont12
|
|
|
- reverseButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- if let btnClickClosure = self?.btnClickClosure {
|
|
|
- btnClickClosure(BtnActionType.reverse)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
- return reverseButton
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var musicButton: UIButton = {
|
|
|
- let musicButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- musicButton.setImage(kImage(name: "video_ico_music"), for: UIControl.State.normal)
|
|
|
- musicButton.setTitle("音乐", for: UIControl.State.normal)
|
|
|
- musicButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
- musicButton.titleLabel?.font = kRegularFont12
|
|
|
- musicButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- if let btnClickClosure = self?.btnClickClosure {
|
|
|
- btnClickClosure(BtnActionType.music)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
- return musicButton
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var filterButton: UIButton = {
|
|
|
- let filterButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- filterButton.setImage(kImage(name: "video_ico_filter"), for: UIControl.State.normal)
|
|
|
- filterButton.setTitle("滤镜", for: UIControl.State.normal)
|
|
|
- filterButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
- filterButton.titleLabel?.font = kRegularFont12
|
|
|
- filterButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- if let btnClickClosure = self?.btnClickClosure {
|
|
|
- btnClickClosure(BtnActionType.filter)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
- return filterButton
|
|
|
- }()
|
|
|
-
|
|
|
- // MARK:放置"拍摄时长Label"のView
|
|
|
- lazy var timeBackView: UIView = {
|
|
|
- let timeBackView = UIView()
|
|
|
- return timeBackView
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var timeDotView: UIView = {
|
|
|
- let timeDotView = UIView()
|
|
|
- timeDotView.backgroundColor = kFF5E5EColor
|
|
|
- timeDotView.cornerRadius = 4
|
|
|
- timeDotView.masksToBounds = true
|
|
|
- return timeDotView
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var timeLabel: UILabel = {
|
|
|
- let timeLabel = UILabel()
|
|
|
- timeLabel.textColor = kffffffColor
|
|
|
- timeLabel.font = kRegularFont14
|
|
|
- timeLabel.textAlignment = .left
|
|
|
- timeLabel.numberOfLines = 1
|
|
|
- return timeLabel
|
|
|
- }()
|
|
|
-
|
|
|
- // MARK:放置"回删、确定"のView
|
|
|
- lazy var selBackView: UIView = {
|
|
|
- let selBackView = UIView()
|
|
|
- return selBackView
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var delButton: UIButton = {
|
|
|
- let delButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- delButton.setImage(kImage(name: "video_btn_delete"), for: UIControl.State.normal)
|
|
|
- delButton.setTitle("回删", for: UIControl.State.normal)
|
|
|
- delButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
- delButton.titleLabel?.font = kRegularFont12
|
|
|
- delButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- if let btnClickClosure = self?.btnClickClosure {
|
|
|
- btnClickClosure(BtnActionType.delete)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
- return delButton
|
|
|
- }()
|
|
|
-
|
|
|
- private lazy var confirmButton: UIButton = {
|
|
|
- let confirmButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- confirmButton.setImage(kImage(name: "video_btn_submit"), for: UIControl.State.normal)
|
|
|
- confirmButton.setTitle("确定", for: UIControl.State.normal)
|
|
|
- confirmButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
|
|
|
- confirmButton.titleLabel?.font = kRegularFont12
|
|
|
- confirmButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- if let btnClickClosure = self?.btnClickClosure {
|
|
|
- btnClickClosure(BtnActionType.confirm)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
- return confirmButton
|
|
|
- }()
|
|
|
-
|
|
|
- // MARK:progressView
|
|
|
- lazy var progressView: QUProgressView = {
|
|
|
- let progressView = QUProgressView(frame: CGRect(x: 14, y: kSafeStatusBarHeight-20+40, width: kScreenWidth-28, height: 5))
|
|
|
- progressView.showBlink = false
|
|
|
- progressView.showNoticePoint = true
|
|
|
- progressView.backgroundColor = kRGBAColor(r: 0/255.0, g: 0/255.0, b: 0/255.0, a: 0.3)
|
|
|
- progressView.cornerRadius = 2
|
|
|
- progressView.masksToBounds = true
|
|
|
-
|
|
|
- progressView.colorProgress = kffffffColor
|
|
|
- progressView.colorNotice = UIColor.red
|
|
|
- progressView.colorSepatorPoint = k62CC74Color
|
|
|
-
|
|
|
- return progressView
|
|
|
- }()
|
|
|
-
|
|
|
- // MARK:录制のButton
|
|
|
- private lazy var recordButton: UIButton = {
|
|
|
- let recordButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
- recordButton.setImage(kImage(name: "video_btn_shoot"), for: UIControl.State.normal)
|
|
|
- recordButton.setImage(kImage(name: "video_btn_pause"), for: UIControl.State.selected)
|
|
|
- recordButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- recordButton.isSelected = !recordButton.isSelected
|
|
|
- if let videoClosure = self?.videoClosure {
|
|
|
- let isRecord: Int = recordButton.isSelected == true ? 1 : 0
|
|
|
- videoClosure(isRecord)
|
|
|
- }
|
|
|
- }).disposed(by: disposeBag)
|
|
|
-
|
|
|
- return recordButton
|
|
|
- }()
|
|
|
-
|
|
|
-
|
|
|
- // MARK:预览View
|
|
|
- lazy var previewView: UIView = {
|
|
|
- let previewView = UIView()
|
|
|
- return previewView
|
|
|
- }()
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// MARK: - 视图状态处理
|
|
|
-extension PublishVideoView {
|
|
|
- // 刷新进度条进度
|
|
|
- func recordingPercent(percent: CGFloat) {
|
|
|
- progressView.updateProgress(percent)
|
|
|
-
|
|
|
- // if recording {
|
|
|
- let d: Int = Int(percent)
|
|
|
- let m: Int = Int(d / 60)
|
|
|
- let s: Int = Int(d % 60)
|
|
|
-
|
|
|
- timeLabel.text = String(format: "%02d:%02d", m, s)
|
|
|
- // }
|
|
|
-
|
|
|
- if percent == 0 {
|
|
|
- progressView.reset()
|
|
|
- timeLabel.text = ""
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 显示默认视图
|
|
|
- */
|
|
|
- func preRecordViewShow() {
|
|
|
- backButton.isHidden = false
|
|
|
- recordButton.isHidden = false
|
|
|
- progressView.isHidden = false
|
|
|
-
|
|
|
- controlBackView.isHidden = false
|
|
|
- segmentedView.isHidden = false
|
|
|
- timeBackView.isHidden = true
|
|
|
- selBackView.isHidden = true
|
|
|
- }
|
|
|
- /**
|
|
|
- * 显示正在拍摄视图
|
|
|
- */
|
|
|
- func recordingViewShow() {
|
|
|
- backButton.isHidden = false
|
|
|
- recordButton.isHidden = false
|
|
|
- progressView.isHidden = false
|
|
|
-
|
|
|
- controlBackView.isHidden = true
|
|
|
- segmentedView.isHidden = true
|
|
|
- timeBackView.isHidden = false
|
|
|
- selBackView.isHidden = true
|
|
|
- }
|
|
|
- /**
|
|
|
- * 显示暂停拍摄视图
|
|
|
- */
|
|
|
- func pauseViewShow() {
|
|
|
- backButton.isHidden = false
|
|
|
- recordButton.isHidden = false
|
|
|
- progressView.isHidden = false
|
|
|
-
|
|
|
- controlBackView.isHidden = false
|
|
|
- segmentedView.isHidden = false
|
|
|
- timeBackView.isHidden = true
|
|
|
- selBackView.isHidden = false
|
|
|
- }
|
|
|
- /**
|
|
|
- * 显示编辑音乐视图
|
|
|
- */
|
|
|
- func editMusicViewShow() {
|
|
|
- backButton.isHidden = true
|
|
|
- recordButton.isHidden = true
|
|
|
- progressView.isHidden = true
|
|
|
-
|
|
|
- controlBackView.isHidden = true
|
|
|
- segmentedView.isHidden = true
|
|
|
- selBackView.isHidden = true
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-extension PublishVideoView : JXSegmentedViewDelegate {
|
|
|
-
|
|
|
- // 点击选中的情况才会调用该方法
|
|
|
- func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
|
|
|
- print("----选中\(index)")
|
|
|
- }
|
|
|
-
|
|
|
- /// 是否允许点击选中目标index的item
|
|
|
- func segmentedView(_ segmentedView: JXSegmentedView, canClickItemAt index: Int) -> Bool {
|
|
|
- return true
|
|
|
- }
|
|
|
-}
|
|
|
-
|