VPCamera3/SwiftProject/SwiftProject/CCKit/Base/BaseVirtualController.swift

601 lines
22 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// BaseVirtualController.swift
// SwiftProject
//
// Created by soldoros on 2024/1/10.
//
import UIKit
class BaseVirtualController: UIViewController {
///
var navtionBar:UIImageView?
var navtionImgView:UIImageView?
/// 线
var navLine:UIView?
///
var titleLab:UILabel?
/// logo
var titleImgView:UIImageView?
///
var titleButton:UIButton?
///
var leftBtn1:UIButton?
var leftBtn2:UIButton?
///
var rightBtn1:UIButton?
var rightBtn2:UIButton?
///
var redView:UIView?
///
var page:NSInteger?
///
var loadingView:CCRequestLoadingView?
//
var indicatorView : UIActivityIndicatorView?
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(userVipStateChangeNotification(noti:)), name: Notification.Name(rawValue: "kUserVipStateChangeNotification"), object: nil)
}
//vip
@objc func userVipStateChangeNotification(noti:Notification) {
print("父类收到的vip通知...")
}
//=========================================
//
//10 11 12 13 14
//=========================================
///
///
/// - Parameter string:
public func setNavgationBarImg(string:NSString){
if(navtionBar == nil){
navtionBar = UIImageView.init()
navtionBar?.frame = CGRect.init(x: 0, y: 0, width: SCREEN_Width, height: SafeAreaTop_Height)
navtionBar?.isUserInteractionEnabled = true
view.addSubview(navtionBar!)
}
if(navtionImgView == nil){
navtionImgView = UIImageView.init()
navtionImgView?.frame = (navtionBar?.bounds)!
navtionImgView?.isUserInteractionEnabled = true
view.addSubview(navtionImgView!)
}
navtionImgView?.image = UIImage.init(named: string as String)
}
///
///
/// - Parameter color:
public func setNavgationBarColor(color:UIColor){
if(navtionBar == nil){
navtionBar = UIImageView.init()
navtionBar?.frame = CGRect.init(x: 0, y: 0, width: SCREEN_Width, height: SafeAreaTop_Height)
navtionBar?.isUserInteractionEnabled = true
view.addSubview(navtionBar!)
}
if(navtionImgView == nil){
navtionImgView = UIImageView.init()
navtionImgView?.frame = (navtionBar?.bounds)!
navtionImgView?.isUserInteractionEnabled = true
view.addSubview(navtionImgView!)
}
navtionImgView?.image = nil
navtionImgView?.backgroundColor = color
}
///
///
/// - Parameter color:
public func setNavgationBarColorImg(color:UIColor){
if(navtionBar == nil){
navtionBar = UIImageView.init()
// navtionBar?.frame = CGRect.init(x: 0, y: 0, width: SCREEN_Width, height: SafeAreaTop_Height)
navtionBar?.isUserInteractionEnabled = true
view.addSubview(navtionBar!)
navtionBar?.snp.makeConstraints { make in
make.left.top.right.equalToSuperview()
make.height.equalTo(SafeAreaTop_Height)
}
}
if(navtionImgView == nil){
navtionImgView = UIImageView.init()
navtionImgView?.frame = (navtionBar?.bounds)!
navtionImgView?.isUserInteractionEnabled = true
navtionBar?.addSubview(navtionImgView!)
}
navtionImgView?.image = UIImage.imageFromColorSwift(color: color)
}
/// 线
///
/// - Parameter color:
public func setNavgationBarLine(color:UIColor){
if(navtionImgView == nil){return}
if(navLine == nil){
navLine = UIView.init()
navLine?.frame = CGRect.init(x: 0, y: 0, width: SCREEN_Width, height: 0.5)
navLine?.bottom = (navtionImgView?.height)!
navtionImgView?.addSubview(navLine!)
}
navLine?.backgroundColor = color
}
///
public func setNavgationNil(){
if(navtionBar != nil){
navtionBar?.removeFromSuperview()
navtionBar = nil
}
}
///
///
/// - Parameters:
/// - font:
/// - color:
public func setNavgationTitleAttribute(font:UIFont,color:UIColor){
if(titleLab == nil){
titleLab = UILabel.init()
titleLab?.frame = CGRect.init(x: 0, y: StatuBar_Height, width: SCREEN_Width, height: NavBar_Height)
titleLab?.textAlignment = NSTextAlignment.center
navtionImgView?.addSubview(titleLab!)
titleLab?.isUserInteractionEnabled = true
}
titleLab?.font = font
titleLab?.textColor = color
}
///
///
/// - Parameter string:
public func setNavgaionTitle(string:String){
if(titleLab == nil){
titleLab = UILabel.init()
// titleLab?.frame = CGRect.init(x: 0, y: StatuBar_Height, width: SCREEN_Width, height: NavBar_Height)
titleLab?.textAlignment = NSTextAlignment.center
navtionImgView?.addSubview(titleLab!)
titleLab?.isUserInteractionEnabled = true
}
titleLab?.text = string
titleLab?.sizeToFit()
// if((titleLab?.width)! > SCREEN_Width-100){
titleLab?.width = 100
// }
titleLab?.centerX = (navtionImgView?.width)! * 0.5
titleLab?.centerY = StatuBar_Height + NavBar_Height * 0.5;
}
public func setNavgationTitleForCaptureVC(string:String) {
setNavgaionTitle(string: string)
titleLab?.backgroundColor = .red
titleLab?.layer.cornerRadius = 2
titleLab?.layer.masksToBounds = true
}
/// logo
///
/// - Parameter imgStr:
public func setNavgaionTitleImg(imgStr:NSString){
if(titleImgView == nil){
titleImgView = UIImageView.init()
titleImgView?.frame = CGRect.init(x: 0, y: StatuBar_Height, width: (NavBar_Height - 25) * 63/22, height: NavBar_Height - 25)
navtionImgView?.addSubview(titleImgView!)
navtionImgView?.isUserInteractionEnabled = true
titleImgView?.centerX = (navtionImgView?.width)! * 0.5
titleImgView?.centerY = StatuBar_Height + NavBar_Height * 0.5
}
titleImgView?.image = UIImage.init(named: imgStr as String)
}
///
///
/// - Parameter string:
public func setNavgaionTitleButton(string:NSString){
if(titleButton == nil){
titleButton = UIButton.init(type: UIButton.ButtonType.custom)
titleButton?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: SCREEN_Width * 0.5, height: NavBar_Height - 10)
titleButton?.centerX = (navtionImgView?.width)! * 0.5
titleButton?.centerY = StatuBar_Height + NavBar_Height * 0.5
navtionImgView?.addSubview(titleButton!)
titleButton?.tag = 10
titleButton?.isUserInteractionEnabled = true
titleButton?.setTitleColor(UIColor.hexStringToColor(hexString: "333333"), for: UIControl.State.normal)
titleButton?.setImage(UIImage.init(named: "jiantouxia"), for: UIControl.State.normal)
titleButton?.setImage(UIImage.init(named: "jiantoushang"), for: UIControl.State.selected)
titleButton?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
titleButton?.setTitle(string as String, for: UIControl.State.normal)
titleButton?.setImgTitleCenteredAround()
}
///
///
/// - Parameter imgStr:
public func setLeftOneBtnImg(imgStr:NSString){
if(leftBtn1 == nil){
leftBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
navtionBar?.addSubview(leftBtn1!)
leftBtn1?.tag = 12
leftBtn1?.isSelected = false
leftBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
leftBtn1?.snp.makeConstraints({ (make) in
make.width.equalTo(NavBar_Height)
make.height.equalTo(NavBar_Height)
make.left.equalTo(0)
make.top.equalTo(StatuBar_Height)
})
}
let img:UIImage = UIImage.init(named: imgStr as String)!
leftBtn1?.setImage(img, for: UIControl.State.normal)
}
///
///
/// - Parameters:
/// - imgStr:
/// - color:
public func setLeftOneBtnImg(imgStr:NSString,color:UIColor){
if(leftBtn1 == nil){
leftBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
leftBtn1?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
leftBtn1?.left = 0
leftBtn1?.top = StatuBar_Height
navtionBar?.addSubview(leftBtn1!)
leftBtn1?.tag = 10
leftBtn1?.isSelected = false
leftBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
var img:UIImage = UIImage.init(named: imgStr as String)!
img = img.imageWithColorSwift(color: color)
leftBtn1?.setImage(img, for: UIControl.State.normal)
}
///
///
/// - Parameter string:
public func setLeftOneBtnTitle(string:NSString){
if(leftBtn1 == nil){
leftBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
leftBtn1?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: 50, height: NavBar_Height)
navtionBar?.addSubview(leftBtn1!)
leftBtn1?.tag = 10
leftBtn1?.isSelected = false
leftBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
leftBtn1?.left = 15
leftBtn1?.top = StatuBar_Height
leftBtn1?.setTitleColor(UIColor.white, for: UIControl.State.normal)
leftBtn1?.setTitleColor(UIColor.white, for: UIControl.State.selected)
leftBtn1?.titleLabel?.textAlignment = NSTextAlignment.center
leftBtn1?.titleLabel?.font = UIFont.systemFont(ofSize: 16)
leftBtn1?.setTitle(string as String, for: UIControl.State.normal)
}
///
///
/// - Parameters:
/// - imgStr1:
/// - imgStr2:
public func setLeftBtnImg(imgStr1:NSString,imgStr2:NSString){
if(leftBtn1 == nil){
leftBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
leftBtn1?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
leftBtn1?.left = 0
leftBtn1?.top = StatuBar_Height
navtionBar?.addSubview(leftBtn1!)
leftBtn1?.tag = 10
leftBtn1?.isSelected = false
leftBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
if(leftBtn2 == nil){
leftBtn2 = UIButton.init(type: UIButton.ButtonType.custom)
leftBtn2?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
leftBtn2?.left = (leftBtn1?.right)!
leftBtn2?.top = StatuBar_Height
navtionBar?.addSubview(leftBtn2!)
leftBtn2?.tag = 11
leftBtn2?.isSelected = false
leftBtn2?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
leftBtn1?.setImage(UIImage.init(named: imgStr1 as String), for: UIControl.State.normal)
leftBtn2?.setImage(UIImage.init(named: imgStr2 as String), for: UIControl.State.normal)
}
///
///
/// - Parameter imgStr:
public func setRightOneBtnImg(imgStr:NSString){
if(rightBtn1 == nil){
rightBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
rightBtn1?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
rightBtn1?.right = (navtionBar?.width)! - 5
rightBtn1?.top = StatuBar_Height
navtionBar?.addSubview(rightBtn1!)
rightBtn1?.tag = 12
rightBtn1?.isSelected = false
rightBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
rightBtn1?.setImage(UIImage.init(named: imgStr as String), for: UIControl.State.normal)
}
///
///
/// - Parameters:
/// - imgStr:
/// - color:
public func setRightOneBtnImg(imgStr:NSString,color:UIColor){
if(rightBtn1 == nil){
rightBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
rightBtn1?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
rightBtn1?.right = SCREEN_Width - 5
rightBtn1?.top = StatuBar_Height
navtionBar?.addSubview(rightBtn1!)
rightBtn1?.tag = 12
rightBtn1?.isSelected = false
rightBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
var img:UIImage = UIImage.init(named: imgStr as String)!
img = img.imageWithColorSwift(color: color)
rightBtn1?.setImage(img, for: UIControl.State.normal)
}
///
///
/// - Parameter string:
public func setRightOneBtnTitle(string:NSString){
if(rightBtn1 == nil){
rightBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
navtionBar?.addSubview(rightBtn1!)
rightBtn1?.tag = 12
rightBtn1?.isSelected = false
rightBtn1?.setTitleColor(UIColor.hexStringToColor(hexString: "#ffffff"), for: UIControl.State.normal)
rightBtn1?.setTitleColor(UIColor.hexStringToColor(hexString: "#ffffff"), for: UIControl.State.selected)
rightBtn1?.titleLabel?.textAlignment = NSTextAlignment.right
rightBtn1?.titleLabel?.font = UIFont.systemFont(ofSize: 16)
rightBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
rightBtn1?.snp.makeConstraints({ (make) in
make.right.equalTo(-10)
make.centerY.equalTo(StatuBar_Height + ((navtionBar?.height)! - StatuBar_Height) * 0.5)
})
}
rightBtn1?.isHidden = true
rightBtn1?.setTitle(string as String, for: UIControl.State.normal)
}
///
///
/// - Parameters:
/// - imgStr1:
/// - imgStr2:
public func setRightBtnImg(imgStr1:NSString,imgStr2:NSString){
if(rightBtn1 == nil){
rightBtn1 = UIButton.init(type: UIButton.ButtonType.custom)
rightBtn1?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
rightBtn1?.right = (navtionBar?.width)!
rightBtn1?.top = StatuBar_Height
navtionBar?.addSubview(rightBtn1!)
rightBtn1?.tag = 12
rightBtn1?.isSelected = false
rightBtn1?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
if(rightBtn2 == nil){
rightBtn2 = UIButton.init(type: UIButton.ButtonType.custom)
rightBtn2?.bounds = CGRect.init(x: 0, y: StatuBar_Height, width: NavBar_Height, height: NavBar_Height)
rightBtn2?.right = (rightBtn1?.left)!
rightBtn2?.top = StatuBar_Height
navtionBar?.addSubview(rightBtn2!)
rightBtn1?.tag = 13
rightBtn2?.isSelected = false
rightBtn2?.addTarget(self, action: #selector(navgationButtonClick(sender:)), for: UIControl.Event.touchUpInside)
}
rightBtn1?.setImage(UIImage.init(named: imgStr1 as String), for: UIControl.State.normal)
rightBtn2?.setImage(UIImage.init(named: imgStr2 as String), for: UIControl.State.normal)
}
//=========================================
//
//=========================================
///
///
/// - Parameters:
/// - nomImg:
/// - selImg:
/// - title1:
/// - title2:
/// - color1:
/// - color2:
public func setTabBarItem(nomImg:NSString, selImg:NSString, title1:NSString, title2:NSString, color1:UIColor, color2:UIColor){
}
//=========================================
//
//=========================================
///
///
/// - Parameter phone:
public func callPhone(phone:NSString){
}
///
public func setRedViewOnRightButton(){
}
///
public func deleteRedView(){
}
///
///
/// - Parameter message:
public func showTime(message:NSString){
let imgView:UIImageView = UIImageView()
imgView.frame = CGRect.init(x: 0, y: 0, width: view.width * 0.66, height: view.width * 0.66 * 0.3)
imgView.centerX = view.width * 0.5
imgView.bottom = view.height * 0.5
imgView.image = UIImage.init(named: "showtime")
self.view.addSubview(imgView)
self.view.bringSubviewToFront(imgView)
let lab:UILabel = UILabel()
lab.frame = imgView.bounds
lab.width = imgView.width - 20
lab.centerX = imgView.width * 0.5
imgView.addSubview(lab)
lab.font = UIFont.systemFont(ofSize: 14)
lab.textAlignment = NSTextAlignment.center
lab.numberOfLines = 2
lab.textColor = UIColor.white
lab.text = message as String
imgView.animateIn()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.2, execute:{
UIView.animate(withDuration: 0.3, animations: {
imgView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01);
}, completion: { (bool) in
imgView.removeFromSuperview()
})
})
}
///
/// 10 11 12 13 14
@objc public func navgationButtonClick(sender:UIButton){
print("nihao")
}
//
func addSysIndicatorView(){
if(self.indicatorView == nil){
self.indicatorView = UIActivityIndicatorView.init(style: UIActivityIndicatorView.Style.large)
self.view.addSubview(self.indicatorView!)
}
//frame
self.indicatorView!.bounds = CGRect(x: 0, y: 0, width: 80, height: 80)
self.indicatorView!.centerY = SCREEN_Height * 0.5
self.indicatorView!.centerX = SCREEN_Width * 0.5
self.indicatorView!.clipsToBounds = true
self.indicatorView!.layer.cornerRadius = 5
//
self.indicatorView!.color = UIColor.white
//
self.indicatorView!.backgroundColor = UIColor.hexStringToColor(hexString: "#333333")
//YES
self.indicatorView!.hidesWhenStopped = false
self.indicatorView!.startAnimating()
}
func deleteSysIndicatorView(){
if(self.indicatorView != nil){
self.indicatorView!.stopAnimating()
self.indicatorView!.removeFromSuperview()
self.indicatorView = nil;
}
}
}