|
@@ -0,0 +1,271 @@
|
|
|
+//
|
|
|
+// BFSubtitleSettingView.swift
|
|
|
+// BFRecordScreenKit
|
|
|
+//
|
|
|
+// Created by ak on 2021/12/7.
|
|
|
+// 功能:设置字幕操作面板
|
|
|
+
|
|
|
+import Foundation
|
|
|
+import BFFramework
|
|
|
+import BFCommonKit
|
|
|
+
|
|
|
+typealias SubtitleSettingCallBack = (_ subtitileSettingModel: BFSubtitileSettingModel?) -> Void
|
|
|
+
|
|
|
+class BFSubtitleSettingView: UIView {
|
|
|
+
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //最后一次选择的样式 BTN
|
|
|
+ var lastSelectStyleBtn:UIButton = UIButton.init();
|
|
|
+ //最后一次选择的位置 BTN
|
|
|
+ var lastSelectPointBtn:UIButton = UIButton.init();
|
|
|
+ //最后一次选择的字号的 BTN
|
|
|
+ var lastSelectwordSizeBtn:UIButton = UIButton.init();
|
|
|
+
|
|
|
+ var subtitleSettingCallBack:SubtitleSettingCallBack?
|
|
|
+
|
|
|
+ var subtitleSetting:BFSubtitileSettingModel = BFSubtitileSettingModel.init()
|
|
|
+
|
|
|
+ override init(frame: CGRect) {
|
|
|
+ super.init(frame: frame)
|
|
|
+
|
|
|
+ self.backgroundColor = UIColor.clear
|
|
|
+ addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hidden)))
|
|
|
+
|
|
|
+ let backView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth))
|
|
|
+ backView.backgroundColor = .black
|
|
|
+ addSubview(backView)
|
|
|
+ backView.snp.makeConstraints { make in
|
|
|
+ make.right.equalTo(self.snp.right)
|
|
|
+ make.bottom.equalTo(self.snp.bottom)
|
|
|
+ make.width.equalTo(cScreenWidth)
|
|
|
+ make.height.equalTo(220)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //字体样式
|
|
|
+ for i in 0...6 {
|
|
|
+ let btn = UIButton(type: .custom)
|
|
|
+ btn.setImage(imageInRecordScreenKit(by: "wordStyle\(i + 1)"), for: .normal)
|
|
|
+// btn.setBackgroundImage(UIImage.init(color:
|
|
|
+// UIColor.hexColor(hexadecimal: "#28BE67")), for: .selected)
|
|
|
+ btn.setBackgroundImage(UIImage.init(color:
|
|
|
+ .black), for: .normal)
|
|
|
+ btn.frame = CGRect.init(x: 18 + i * ( 40 + 10) , y: 22, width: 40, height: 40)
|
|
|
+ if(i == 0){
|
|
|
+ btn.isSelected = true
|
|
|
+ btn.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
|
|
|
+ btn.layer.borderWidth = 1.5
|
|
|
+ lastSelectStyleBtn = btn
|
|
|
+ }
|
|
|
+
|
|
|
+ btn.addTarget(self, action: #selector(styleSetting(sender:)), for: .touchUpInside)
|
|
|
+ backView.addSubview(btn)
|
|
|
+ btn.addCorner(corner: 20.0)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //位置
|
|
|
+ let pointTitle = UILabel()
|
|
|
+ pointTitle.textAlignment = .center
|
|
|
+ pointTitle.font = UIFont.systemFont(ofSize: 15)
|
|
|
+ pointTitle.textColor = .white
|
|
|
+ pointTitle.text = "位置"
|
|
|
+ pointTitle.alpha = 0.6
|
|
|
+ backView.addSubview(pointTitle)
|
|
|
+ pointTitle.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(40)
|
|
|
+ make.height.equalTo(25)
|
|
|
+ make.left.equalToSuperview().offset(16)
|
|
|
+ make.top.equalToSuperview().offset(89)
|
|
|
+ }
|
|
|
+ for i in 0...2 {
|
|
|
+ let pointBtn = UIButton(type: .custom)
|
|
|
+ pointBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#28BE67"), for: .selected)
|
|
|
+ pointBtn.setTitleColor(.white, for: .normal)
|
|
|
+ pointBtn.addTarget(self, action: #selector(pointSetting(sender:)), for: .touchUpInside)
|
|
|
+ pointBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#1A1A1A")
|
|
|
+ if(i == 0){
|
|
|
+ pointBtn.isSelected = true
|
|
|
+ pointBtn.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
|
|
|
+ pointBtn.layer.borderWidth = 1.5
|
|
|
+ lastSelectPointBtn = pointBtn
|
|
|
+ pointBtn.setTitle("下", for: .normal)
|
|
|
+ }else if(i == 1){
|
|
|
+ pointBtn.setTitle("中", for: .normal)
|
|
|
+ }else{
|
|
|
+ pointBtn.setTitle("上", for: .normal)
|
|
|
+ }
|
|
|
+ pointBtn.addCorner(corner:10)
|
|
|
+ pointBtn.tag = i
|
|
|
+ backView.addSubview(pointBtn)
|
|
|
+ pointBtn.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(40)
|
|
|
+ make.height.equalTo(30)
|
|
|
+ make.centerX.equalTo(pointTitle.snp.centerX).offset(60 + i * (Int(40 + 10)))
|
|
|
+
|
|
|
+ make.centerY.equalTo(pointTitle.snp.centerY)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //字号
|
|
|
+ let wordSizeTitle = UILabel()
|
|
|
+ wordSizeTitle.textAlignment = .center
|
|
|
+ wordSizeTitle.font = UIFont.systemFont(ofSize: 15)
|
|
|
+ wordSizeTitle.textColor = .white
|
|
|
+ wordSizeTitle.text = "字号"
|
|
|
+ wordSizeTitle.alpha = 0.6
|
|
|
+ backView.addSubview(wordSizeTitle)
|
|
|
+ wordSizeTitle.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(40)
|
|
|
+ make.height.equalTo(25)
|
|
|
+ make.right.equalToSuperview().offset(-100)
|
|
|
+ make.top.equalTo(pointTitle.snp.top)
|
|
|
+ }
|
|
|
+ for i in 0...1 {
|
|
|
+ let wordSizeBtn = UIButton(type: .custom)
|
|
|
+ wordSizeBtn.addTarget(self, action: #selector(wordSizeSetting(sender:)), for: .touchUpInside)
|
|
|
+ wordSizeBtn.backgroundColor = UIColor.hexColor(hexadecimal: "#1A1A1A")
|
|
|
+ wordSizeBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#28BE67"), for: .selected)
|
|
|
+ wordSizeBtn.setTitleColor(.white, for: .normal)
|
|
|
+ wordSizeBtn.setTitle(i == 0 ? "-" : "+", for: .normal)
|
|
|
+ backView.addSubview(wordSizeBtn)
|
|
|
+ wordSizeBtn.tag = i
|
|
|
+ if(i == 0){
|
|
|
+ wordSizeBtn.isSelected = true
|
|
|
+ wordSizeBtn.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
|
|
|
+ wordSizeBtn.layer.borderWidth = 1.5
|
|
|
+ lastSelectwordSizeBtn = wordSizeBtn
|
|
|
+ }
|
|
|
+ wordSizeBtn.addCorner(corner:10)
|
|
|
+ wordSizeBtn.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(30)
|
|
|
+ make.height.equalTo(30)
|
|
|
+ make.left.equalTo(wordSizeTitle.snp.right).offset( 10 + i * (Int(30 + 10)))
|
|
|
+
|
|
|
+ make.centerY.equalTo(pointTitle.snp.centerY)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ //就是一个线
|
|
|
+ let line = UIView.init()
|
|
|
+ line.backgroundColor = UIColor.hexColor(hexadecimal: "#121212")
|
|
|
+ backView.addSubview(line)
|
|
|
+
|
|
|
+ line.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(340)
|
|
|
+ make.height.equalTo(2)
|
|
|
+ make.left.equalToSuperview().offset(18)
|
|
|
+ make.top.equalTo(wordSizeTitle.snp.bottom).offset(23)
|
|
|
+ }
|
|
|
+
|
|
|
+ //不显示字幕
|
|
|
+ let disabelTitle = UILabel()
|
|
|
+ disabelTitle.textAlignment = .left
|
|
|
+ disabelTitle.font = UIFont.boldSystemFont(ofSize: 17)
|
|
|
+ disabelTitle.textColor = .white
|
|
|
+ disabelTitle.text = "不显示字幕"
|
|
|
+ backView.addSubview(disabelTitle)
|
|
|
+ disabelTitle.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(100)
|
|
|
+ make.height.equalTo(24)
|
|
|
+ make.left.equalToSuperview().offset(18)
|
|
|
+ make.top.equalTo(line.snp.top).offset(17)
|
|
|
+ }
|
|
|
+ // 创建switch
|
|
|
+ let disabeSwitch = UISwitch()
|
|
|
+ disabeSwitch.isOn = false
|
|
|
+ backView.addSubview(disabeSwitch)
|
|
|
+ disabeSwitch.addTarget(self, action: #selector(switchChange(uiswitch:)), for: .valueChanged)
|
|
|
+ disabeSwitch.snp.makeConstraints { make in
|
|
|
+ make.width.equalTo(51)
|
|
|
+ make.height.equalTo(31)
|
|
|
+ make.right.equalToSuperview().offset(-18)
|
|
|
+ make.top.equalTo(line.snp.top).offset(13)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // addCorner(roundingCorners: .topLeft, corner: 10)
|
|
|
+ // addCorner(roundingCorners: .topRight, corner: 10)
|
|
|
+ BFLog(message: "")
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func hidden(){
|
|
|
+ self.isHidden = true
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func styleSetting(sender: UIButton){
|
|
|
+ lastSelectStyleBtn.isSelected = false
|
|
|
+ lastSelectStyleBtn.layer.borderColor = UIColor.clear.cgColor
|
|
|
+
|
|
|
+ sender.isSelected = true
|
|
|
+ lastSelectStyleBtn = sender
|
|
|
+
|
|
|
+ sender.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
|
|
|
+ sender.layer.borderWidth = 1.5
|
|
|
+
|
|
|
+ subtitleSetting.subtitleStyle = sender.tag
|
|
|
+ }
|
|
|
+ @objc func pointSetting(sender:UIButton){
|
|
|
+
|
|
|
+ lastSelectPointBtn.isSelected = false
|
|
|
+ lastSelectPointBtn.layer.borderColor = UIColor.clear.cgColor
|
|
|
+
|
|
|
+ sender.isSelected = true
|
|
|
+ lastSelectPointBtn = sender
|
|
|
+
|
|
|
+ sender.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
|
|
|
+ sender.layer.borderWidth = 1.5
|
|
|
+
|
|
|
+ subtitleSetting.subtitlePoint = sender.tag
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ @objc func wordSizeSetting(sender:UIButton){
|
|
|
+
|
|
|
+ lastSelectwordSizeBtn.isSelected = false
|
|
|
+ lastSelectwordSizeBtn.layer.borderColor = UIColor.clear.cgColor
|
|
|
+
|
|
|
+ sender.isSelected = true
|
|
|
+ lastSelectwordSizeBtn = sender
|
|
|
+
|
|
|
+ sender.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
|
|
|
+ sender.layer.borderWidth = 1.5
|
|
|
+ if(sender.tag == 0){
|
|
|
+ subtitleSetting.subtitleSize -= 10
|
|
|
+ }else{
|
|
|
+ subtitleSetting.subtitleSize += 10
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ @objc func switchChange(uiswitch:UISwitch) {
|
|
|
+ print("字幕开关状态\(uiswitch.isOn )")
|
|
|
+
|
|
|
+ subtitleSetting.subtitleIsShow = !uiswitch.isOn
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class BFSubtitileSettingModel: NSObject {
|
|
|
+
|
|
|
+ //字幕样式 值说明0 1 2 3 4 5 6
|
|
|
+ var subtitleStyle:Int = 0
|
|
|
+ //字幕位置 值说明 0 下 1 中 2 上
|
|
|
+ var subtitlePoint:Int = 0
|
|
|
+
|
|
|
+ //字幕文字大小 60px
|
|
|
+ var subtitleSize:Int = 60
|
|
|
+
|
|
|
+ //字幕是否显示
|
|
|
+ var subtitleIsShow:Bool = true
|
|
|
+
|
|
|
+}
|