jsdw_ios/QuickLocation/Section/Scan/ScanView.swift

129 lines
3.6 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.

//
// ScanView.swift
// QuickLocation
//
// Created by on 2026/6/2.
//
import UIKit
import RxSwift
import RxCocoa
import AVFoundation
class ScanView: UIView {
var disposeBag = DisposeBag()
private func setupRx() {
backBtn.rx.tap.subscribe(onNext: { _ in
AppRouter.shared.popOrDismiss()
}).disposed(by: disposeBag)
torchBtn.rx.tap.subscribe(onNext: { _ in
guard let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else { return }
do {
try device.lockForConfiguration()
device.torchMode = device.torchMode == .on ? .off : .on
device.unlockForConfiguration()
} catch {
DLToast.show(text: "闪光灯开启失败")
}
}).disposed(by: disposeBag)
}
private func setupUI() {
addSubview(navBarView)
navBarView.addSubview(backBtn)
navBarView.addSubview(torchBtn)
addSubview(scanBoxView)
scanBoxView.addSubview(scanImgView)
scanBoxView.addSubview(scanLineView)
navBarView.layoutChain
.edges(excludingEdge: .bottom)
.height(kNaviHeight)
backBtn.layoutChain
.top(kStatusBarHeight + 12)
.left(15)
.width(35)
.height(24)
torchBtn.layoutChain
.centerY(backBtn)
.right(15)
.width(100)
.height(24)
scanBoxView.layoutChain
.centerY()
.edgesHorzontal(35)
.heightToWidth(1)
scanImgView.layoutChain.edges()
// scanLineView frame AutoLayout
}
override func layoutSubviews() {
super.layoutSubviews()
scanLineView.frame = CGRect(x: 5, y: 0, width: scanBoxView.bounds.width - 10, height: 2)
}
lazy var navBarView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var backBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("取消", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.extendEdgeInsets = UIEdgeInsets(top: 54, left: 15, bottom: 100, right: 100)
return btn
}()
lazy var torchBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("打开手电筒", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.extendEdgeInsets = UIEdgeInsets(top: 54, left: 15, bottom: 100, right: 100)
return btn
}()
lazy var scanBoxView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var scanImgView: UIImageView = {
let view = UIImageView()
view.backgroundColor = .clear
view.image = UIImage(named: "Scan/scan")
view.contentMode = .scaleAspectFill
return view
}()
lazy var scanLineView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#16B3FF")
return view
}()
override init(frame: CGRect) {
super.init(frame: .zero)
backgroundColor = .clear
setupUI()
setupRx()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}