123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- //
- // BFSubtitleSettingView.swift
- // BFRecordScreenKit
- //
- // Created by ak on 2021/12/7.
- // 功能:设置字幕操作面板
- import BFCommonKit
- import BFMediaKit
- import BFUIKit
- import Foundation
- import UIKit
- typealias SubtitleSettingCallBack = (_ subtitileModel: PQEditSubTitleModel) -> Void
- class BFSubtitleSettingView: UIView {
- required init?(coder _: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- // 最后一次选择的样式 BTN
- var lastSelectStyleBtn: UIButton = UIButton()
- // 最后一次选择的位置 BTN
- var lastSelectPointBtn: UIButton = UIButton()
-
- var subtitleSettingCallBack: SubtitleSettingCallBack?
- var subtitle: PQEditSubTitleModel = PQEditSubTitleModel()
- // 样式配置
- var styleConfig: [Int: [String: Any]] = Dictionary()
-
- //操作板背景
- let backView = UIButton()
-
- //设置字号配置位置
- var wordSizeIndex:Int = 3
-
- var wordSizeBtnXiao:UIButton?
- var wordSizeBtnDa:UIButton?
- override init(frame: CGRect) {
- super.init(frame: frame)
- backgroundColor = UIColor.clear
- addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hidden)))
- 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)
- }
- backView.setNeedsUpdateConstraints()
-
- styleConfig = [0: ["fontColor": UIColor.hexColor(hexadecimal: "#FFFFFF"), "backgroundColor": UIColor.clear, "strokeColor": UIColor.black, "backgroundAlpha": 0.0,"strokeWidth":10.4,"subtitleSize":40],
- 1: ["fontColor": UIColor.hexColor(hexadecimal: "#FF9292"), "backgroundColor": UIColor.clear, "strokeColor": UIColor.black, "backgroundAlpha": 0.0,"strokeWidth":11.6,"subtitleSize":49],
- 2: ["fontColor": UIColor.hexColor(hexadecimal: "#80C2FF"), "backgroundColor": UIColor.clear, "strokeColor": UIColor.black, "backgroundAlpha": 0.0,"strokeWidth":13.4,"subtitleSize":60],
- 3: ["fontColor": UIColor.hexColor(hexadecimal: "#80E4AB"), "backgroundColor": UIColor.clear, "strokeColor": UIColor.black, "backgroundAlpha": 0.0,"strokeWidth":14.6,"subtitleSize":69],
- 4: ["fontColor": UIColor.hexColor(hexadecimal: "#FFCF53"), "backgroundColor": UIColor.clear, "strokeColor": UIColor.black, "backgroundAlpha": 0.0,"strokeWidth":17.4,"subtitleSize":81],
- 5: ["fontColor": UIColor.hexColor(hexadecimal: "#000000"), "backgroundColor": UIColor.clear, "strokeColor": UIColor.white, "backgroundAlpha": 0.0,"strokeWidth":20.4,"subtitleSize":101],
- 6: ["fontColor": UIColor.hexColor(hexadecimal: "#FFFFFF"), "backgroundColor":UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.6), "strokeColor": UIColor.clear, "backgroundAlpha": 0.6,"strokeWidth":23.2,"subtitleSize":121]]
- // 字体样式
- for i in 0...6 {
- let btn = UIButton(type: .custom)
- btn.setImage(imageInRecordScreenKit(by: "wordStyle\(i + 1)"), for: .normal)
- btn.setBackgroundImage(UIImage(color: .black), for: .normal)
- btn.frame = CGRect(x: 18 + i * (40 + 10), y: 22, width: 40, height: 40)
- btn.tag = i
- if i == 0 {
- btn.isSelected = true
- btn.layer.borderColor = UIColor.hexColor(hexadecimal: "#389AFF").cgColor
- btn.layer.borderWidth = 1.5
- lastSelectStyleBtn = btn
- styleSetting(sender: lastSelectStyleBtn)
- }
- 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 = "option_location".BFLocale
- 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: "#389AFF"), 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: "#389AFF").cgColor
- pointBtn.layer.borderWidth = 1.5
- lastSelectPointBtn = pointBtn
- pointBtn.setTitle("option_bottom".BFLocale, for: .normal)
- } else if i == 1 {
- pointBtn.setTitle("option_middle".BFLocale, for: .normal)
- } else {
- pointBtn.setTitle("option_top".BFLocale, 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 = "option_size".BFLocale
- wordSizeTitle.alpha = 0.6
- wordSizeTitle.adjustsFontSizeToFitWidth = true
- 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)
- backView.addSubview(wordSizeBtn)
- wordSizeBtn.tag = i
- if(i == 0){
- wordSizeBtnXiao = wordSizeBtn
- }else{
- wordSizeBtnDa = wordSizeBtn
- }
-
- wordSizeBtn.setBackgroundImage(imageInRecordScreenKit(by: i == 0 ? "wordSizeSetting-_h" : "wordSizeSetting+_h"), for: .normal)
-
- wordSizeBtn.snp.makeConstraints { make in
- make.width.equalTo(24)
- make.height.equalTo(24)
- make.left.equalTo(wordSizeTitle.snp.right).offset(10 + i * Int(30 + 10))
- make.centerY.equalTo(pointTitle.snp.centerY)
- }
- }
-
- let config = styleConfig[3]
- subtitle.setting.subtitleSize = config?["subtitleSize"] as! Int
- subtitle.setting.strokeWidth = CGFloat(config?["strokeWidth"] as? Double ?? 0.0)
-
- // 就是一个线
- let line = UIView()
- 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 = "option_off".BFLocale
- backView.addSubview(disabelTitle)
- disabelTitle.snp.makeConstraints { make in
- make.right.equalTo(cScreenWidth - 80)
- 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)
- }
- if #available(iOS 13.0, *) { disabeSwitch.subviews.first?.subviews.first?.backgroundColor = UIColor.hexColor(hexadecimal: "#393939") } else if #available(iOS 12.0, *) { disabeSwitch.subviews.first?.subviews.first?.subviews.first?.backgroundColor = UIColor.hexColor(hexadecimal: "#393939") }
- disabeSwitch.onTintColor = UIColor.hexColor(hexadecimal: "#393939")
-
-
- }
-
- override func layoutSubviews() {
- super.layoutSubviews()
- self.backView.addCorner(roundingCorners: [.topLeft, .topRight], corner: 10)
- }
- @objc func hidden() {
- 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: "#389AFF").cgColor
- sender.layer.borderWidth = 1.5
- subtitle.setting.subtitleStyle = sender.tag
- let config = styleConfig[sender.tag]
- subtitle.setting.fontColor = config?["fontColor"] as! UIColor
- subtitle.setting.backgroundColor = config?["backgroundColor"] as! UIColor
- subtitle.setting.backgroundAlpha = Float(config?["backgroundAlpha"] as! Double)
- subtitle.setting.strokeColor = config?["strokeColor"] as! UIColor
- if subtitleSettingCallBack != nil {
- subtitleSettingCallBack!(subtitle)
- }
- }
- @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: "#389AFF").cgColor
- sender.layer.borderWidth = 1.5
- subtitle.setting.subtitlePoint = sender.tag
- if subtitleSettingCallBack != nil {
- subtitleSettingCallBack!(subtitle)
- }
- }
- @objc func wordSizeSetting(sender: UIButton) {
- if(sender.tag == 0){
- if(wordSizeIndex == 0){
- BFLog(2, message: "已经到边界最小")
- return
- }
- wordSizeIndex -= 1
- }else if(sender.tag == 1){
- if(wordSizeIndex == 6){
- BFLog(2, message: "已经到边界最大")
- return
- }
- wordSizeIndex += 1
- }
- BFLog(2, message: "wordSizeIndex is\(wordSizeIndex)")
- if(wordSizeIndex == 0){
- wordSizeBtnDa?.setImage(imageInRecordScreenKit(by: "wordSizeSetting+_h"), for: .normal)
- wordSizeBtnXiao?.setImage(imageInRecordScreenKit(by: "wordSizeSetting-_n"), for: .normal)
- }else if(wordSizeIndex == 6){
- wordSizeBtnXiao?.setImage(imageInRecordScreenKit(by: "wordSizeSetting-_h"), for: .normal)
- wordSizeBtnDa?.setImage(imageInRecordScreenKit(by: "wordSizeSetting+_n"), for: .normal)
- }else{
-
- wordSizeBtnXiao?.setImage(imageInRecordScreenKit(by: "wordSizeSetting-_h"), for: .normal)
- wordSizeBtnDa?.setImage(imageInRecordScreenKit(by: "wordSizeSetting+_h"), for: .normal)
- }
-
- let config = styleConfig[wordSizeIndex]
- subtitle.setting.subtitleSize = config?["subtitleSize"] as! Int
- subtitle.setting.strokeWidth = CGFloat(config?["strokeWidth"] as? Double ?? 0.0)
- if subtitleSettingCallBack != nil {
- subtitleSettingCallBack!(subtitle)
- }
- }
- @objc func switchChange(uiswitch: UISwitch) {
- print("字幕开关状态\(uiswitch.isOn)")
- subtitle.setting.subtitleIsShow = !uiswitch.isOn
- uiswitch.thumbTintColor = !uiswitch.isOn ? UIColor.white : UIColor.hexColor(hexadecimal: "#389AFF")
- if subtitleSettingCallBack != nil {
- subtitleSettingCallBack!(subtitle)
- }
- }
- }
|