mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-11 11:55:50 +00:00
Updating tapToFocus
This commit is contained in:
parent
ab5302132f
commit
bd5a0f193b
7 changed files with 106 additions and 42 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# CHANGELOG
|
||||
|
||||
## Version 1.5.0
|
||||
- Added support for front-facing camera tap to adjust exposure
|
||||
- Updated demo application with tap animation
|
||||
|
||||
## Version 1.4.0
|
||||
- Added support for background audio during video capture
|
||||
- Added allowBackgroundAudio property
|
||||
|
|
|
|||
22
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/focus.imageset/Contents.json
vendored
Normal file
22
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/focus.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "focus@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "focus@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/focus.imageset/focus@2x.png
vendored
Normal file
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/focus.imageset/focus@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/focus.imageset/focus@3x.png
vendored
Normal file
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/focus.imageset/focus@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
|
|
@ -63,7 +63,22 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
}
|
||||
|
||||
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint) {
|
||||
print(focusPoint)
|
||||
let focusView = UIImageView(image: #imageLiteral(resourceName: "focus"))
|
||||
focusView.center = focusPoint
|
||||
focusView.alpha = 0.0
|
||||
view.addSubview(focusView)
|
||||
|
||||
UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||
focusView.alpha = 1.0
|
||||
focusView.transform = CGAffineTransform(scaleX: 1.25, y: 1.25)
|
||||
}, completion: { (success) in
|
||||
UIView.animate(withDuration: 0.15, delay: 0.5, options: .curveEaseInOut, animations: {
|
||||
focusView.alpha = 0.0
|
||||
focusView.transform = CGAffineTransform(translationX: 0.6, y: 0.6)
|
||||
}, completion: { (success) in
|
||||
focusView.removeFromSuperview()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func SwiftyCamDidChangeZoomLevel(zoomLevel: CGFloat) {
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ By default, **pinchToZoom** is enabled.
|
|||
|
||||
## Camera Focus
|
||||
|
||||
SwiftyCam, by default, support tap to focus on the video preview. SwiftyCam will set the focus and exposure levels of the session to the tapped point. Autofocus and autoexposure will be resumed once SwiftyCam detects significant movement from the tapped point. To disable this feature, change the `tapToFocus` property:
|
||||
SwiftyCam, by default, support tap to focus on the video preview. SwiftyCam will set the focus and exposure levels of the session to the tapped point. While tap to set exposure is supported on both cameras, tap to focus is only supported on rear facing cameras. Autofocus and autoexposure will be resumed once SwiftyCam detects significant movement from the tapped point. To disable this feature, change the `tapToFocus` property:
|
||||
|
||||
```swift
|
||||
tapToFocus = false
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
public var pinchToZoom = true
|
||||
|
||||
/// Sets whether Tap to Focus is enabled for the capture session
|
||||
/// Sets whether Tap to Focus and Tap to Adjust Exposure is enabled for the capture session
|
||||
|
||||
public var tapToFocus = true
|
||||
|
||||
|
|
@ -127,6 +127,10 @@ open class SwiftyCamViewController: UIViewController {
|
|||
|
||||
public var allowBackgroundAudio = true
|
||||
|
||||
/// Sets whether a double tap to switch cameras is supported
|
||||
|
||||
public var doubleTapCameraSwitch = true
|
||||
|
||||
|
||||
// MARK: Public Get-only Variable Declarations
|
||||
|
||||
|
|
@ -213,7 +217,7 @@ open class SwiftyCamViewController: UIViewController {
|
|||
super.viewDidLoad()
|
||||
previewLayer = PreviewView(frame: self.view.frame)
|
||||
|
||||
// Add Pinch Gesture Recognizer for pinch to zoom
|
||||
// Add Gesture Recognizers
|
||||
|
||||
addGestureRecognizersTo(view: previewLayer)
|
||||
|
||||
|
|
@ -477,43 +481,6 @@ open class SwiftyCamViewController: UIViewController {
|
|||
// If flash is enabled, disable it as the torch is needed for front facing camera
|
||||
disableFlash()
|
||||
}
|
||||
|
||||
|
||||
/// Override Touches Began for Tap to Focus
|
||||
|
||||
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard tapToFocus == true && currentCamera == .rear else {
|
||||
// Ignore taps
|
||||
return
|
||||
}
|
||||
|
||||
let screenSize = previewLayer!.bounds.size
|
||||
if let touchPoint = touches.first {
|
||||
let x = touchPoint.location(in: previewLayer!).y / screenSize.height
|
||||
let y = 1.0 - touchPoint.location(in: previewLayer!).x / screenSize.width
|
||||
let focusPoint = CGPoint(x: x, y: y)
|
||||
|
||||
if let device = videoDevice {
|
||||
do {
|
||||
try device.lockForConfiguration()
|
||||
|
||||
device.focusPointOfInterest = focusPoint
|
||||
device.focusMode = .autoFocus
|
||||
device.exposurePointOfInterest = focusPoint
|
||||
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
|
||||
device.unlockForConfiguration()
|
||||
//Call delegate function and pass in the location of the touch
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.cameraDelegate?.SwiftyCamDidFocusAtPoint(focusPoint: touchPoint.location(in: self.previewLayer))
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// just ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private Functions
|
||||
|
||||
|
|
@ -741,8 +708,54 @@ open class SwiftyCamViewController: UIViewController {
|
|||
}
|
||||
}
|
||||
|
||||
/// Handle single tap gesture
|
||||
|
||||
@objc fileprivate func singleTapGesture(tap: UITapGestureRecognizer) {
|
||||
guard tapToFocus == true else {
|
||||
// Ignore taps
|
||||
return
|
||||
}
|
||||
|
||||
let screenSize = previewLayer!.bounds.size
|
||||
let tapPoint = tap.location(in: previewLayer!)
|
||||
let x = tapPoint.y / screenSize.height
|
||||
let y = 1.0 - tapPoint.x / screenSize.width
|
||||
let focusPoint = CGPoint(x: x, y: y)
|
||||
|
||||
if let device = videoDevice {
|
||||
do {
|
||||
try device.lockForConfiguration()
|
||||
|
||||
if device.isFocusPointOfInterestSupported == true {
|
||||
device.focusPointOfInterest = focusPoint
|
||||
device.focusMode = .autoFocus
|
||||
}
|
||||
device.exposurePointOfInterest = focusPoint
|
||||
device.exposureMode = AVCaptureExposureMode.continuousAutoExposure
|
||||
device.unlockForConfiguration()
|
||||
//Call delegate function and pass in the location of the touch
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.cameraDelegate?.SwiftyCamDidFocusAtPoint(focusPoint: tapPoint)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// just ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle double tap gesture
|
||||
|
||||
@objc fileprivate func doubleTapGesture(tap: UITapGestureRecognizer) {
|
||||
guard doubleTapCameraSwitch == true else {
|
||||
return
|
||||
}
|
||||
switchCamera()
|
||||
}
|
||||
|
||||
/**
|
||||
Add pinch gesture recognizer to currentView
|
||||
Add pinch gesture recognizer and double tap gesture recognizer to currentView
|
||||
|
||||
- Parameter view: View to add gesture recognzier
|
||||
|
||||
|
|
@ -752,6 +765,16 @@ open class SwiftyCamViewController: UIViewController {
|
|||
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(zoomGesture(pinch:)))
|
||||
pinchGesture.delegate = self
|
||||
view.addGestureRecognizer(pinchGesture)
|
||||
|
||||
let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(singleTapGesture(tap:)))
|
||||
singleTapGesture.numberOfTapsRequired = 1
|
||||
singleTapGesture.delegate = self
|
||||
view.addGestureRecognizer(singleTapGesture)
|
||||
|
||||
let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTapGesture(tap:)))
|
||||
doubleTapGesture.numberOfTapsRequired = 2
|
||||
doubleTapGesture.delegate = self
|
||||
view.addGestureRecognizer(doubleTapGesture)
|
||||
}
|
||||
|
||||
/// Handle Denied App Privacy Settings
|
||||
|
|
|
|||
Loading…
Reference in a new issue