123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- //
- // BFSubtitleSettingView.swift
- // BFRecordScreenKit
- //
- // Created by ak on 2021/12/7.
- // 功能:设置字幕操作面板
- import Foundation
- import BFFramework
- import BFCommonKit
- typealias SubtitleSettingCallBack = (_ subtitileModel: PQEditSubTitleModel) -> 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 subtitle:PQEditSubTitleModel = PQEditSubTitleModel.init()
-
- //样式配置
- var styleConfig:Dictionary<Int,Dictionary<String,Any>> = Dictionary.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)
- }
-
- styleConfig = [0:["fontColor":UIColor.hexColor(hexadecimal: "#FFCF53"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
- 1:["fontColor":UIColor.hexColor(hexadecimal: "#FF9292"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
- 2:["fontColor":UIColor.hexColor(hexadecimal: "#80C2FF"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
- 3:["fontColor":UIColor.hexColor(hexadecimal: "#80E4AB"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
- 4:["fontColor":UIColor.hexColor(hexadecimal: "#FFFFFF"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
- 5:["fontColor":UIColor.hexColor(hexadecimal: "#000000"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.white,"backgroundAlpha":0.0],
- 6:["fontColor":UIColor.hexColor(hexadecimal: "#FFFFFF"),"backgroundColor":UIColor.black,"strokeColor":UIColor.black,"backgroundAlpha":0.6]
- ]
-
- //字体样式
- for i in 0...6 {
- let btn = UIButton(type: .custom)
- btn.setImage(imageInRecordScreenKit(by: "wordStyle\(i + 1)"), for: .normal)
- btn.setBackgroundImage(UIImage.init(color:.black), for: .normal)
- btn.frame = CGRect.init(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: "#28BE67").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 = "位置"
- 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
-
- 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: "#28BE67").cgColor
- sender.layer.borderWidth = 1.5
-
- subtitle.setting.subtitlePoint = sender.tag
-
- if(subtitleSettingCallBack != nil){
- subtitleSettingCallBack!(subtitle)
- }
- }
- @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 && subtitle.setting.subtitleSize > 20){
- subtitle.setting.subtitleSize -= 10
- }else if(sender.tag == 1 && subtitle.setting.subtitleSize < 120){
- subtitle.setting.subtitleSize += 10
- }else{
- BFLog(message: "设置字号超出范围!")
- }
- if(subtitleSettingCallBack != nil){
- subtitleSettingCallBack!(subtitle)
- }
-
-
-
- }
- @objc func switchChange(uiswitch:UISwitch) {
- print("字幕开关状态\(uiswitch.isOn )")
-
- subtitle.setting.subtitleIsShow = !uiswitch.isOn
-
- if(subtitleSettingCallBack != nil){
- subtitleSettingCallBack!(subtitle)
- }
- }
- }
|