Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust focal #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Source/LBXScanWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ open class LBXScanWrapper: NSObject,AVCaptureMetadataOutputObjectsDelegate {
setTorch(torch: torch)
}

///调整焦距
open func adjustFocal(value:CGFloat){
let videoConnection:AVCaptureConnection = (self.stillImageOutput.connection(with: .video))!
self.previewLayer?.setAffineTransform(CGAffineTransform(scaleX: 1+value, y: 1+value))
do {
try self.input?.device.lockForConfiguration()
} catch {}
videoConnection.videoScaleAndCropFactor = 1+value
self.input?.device.unlockForConfiguration()
}

//MARK: ------获取系统默认支持的码的类型
static func defaultMetaDataObjectTypes() -> [AVMetadataObject.ObjectType] {
var types =
Expand Down
26 changes: 26 additions & 0 deletions swiftScan/QQScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class QQScanViewController: LBXScanViewController {
@brief 闪关灯开启状态
*/
var isOpenedFlash: Bool = false

/**
@brief 缩放倍数
*/
var scale:CGFloat = 0

// MARK: - 底部几个功能:开启闪光灯、相册、我的二维码

Expand Down Expand Up @@ -114,6 +119,10 @@ class QQScanViewController: LBXScanViewController {
bottomItemsView?.addSubview(btnMyQR)

view.addSubview(bottomItemsView!)

//此处通过手势调整
let pinchGest:UIPinchGestureRecognizer = UIPinchGestureRecognizer.init(target: self, action: #selector(handlePinches(pinchGest:)))
self.view.addGestureRecognizer(pinchGest)
}

//开关闪光灯
Expand All @@ -137,5 +146,22 @@ class QQScanViewController: LBXScanViewController {
let vc = MyCodeViewController()
self.navigationController?.pushViewController(vc, animated: true)
}

@objc func handlePinches(pinchGest:UIPinchGestureRecognizer){

var currentScale:CGFloat = self.scale + pinchGest.scale - 1.0;
if (currentScale > 2) {
currentScale = 2;
}
if (currentScale < 0) {
currentScale = 0;
}
//调整焦距缩放倍数
scanObj?.adjustFocal(value: currentScale)

if pinchGest.state == .ended || pinchGest.state == .cancelled{
self.scale = currentScale
}
}

}