mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
- added the capability to set the maximum zoom scale using the public variable 'maxZoomScale'
- added the possibility to chose, using the public variable 'shouldUseDeviceOrientation', wether the captured media orientation should be inherited by the device or not
This commit is contained in:
parent
9015d60296
commit
ec33ad5a84
4 changed files with 1187 additions and 1121 deletions
|
|
@ -125,7 +125,7 @@
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
1675A9711E00A68300B80903 = {
|
1675A9711E00A68300B80903 = {
|
||||||
CreatedOnToolsVersion = 8.1;
|
CreatedOnToolsVersion = 8.1;
|
||||||
DevelopmentTeam = LW28KCU8N5;
|
DevelopmentTeam = RZ5847N782;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -297,7 +297,7 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
DEVELOPMENT_TEAM = LW28KCU8N5;
|
DEVELOPMENT_TEAM = RZ5847N782;
|
||||||
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
|
|
@ -311,7 +311,7 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
DEVELOPMENT_TEAM = LW28KCU8N5;
|
DEVELOPMENT_TEAM = RZ5847N782;
|
||||||
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,51 @@
|
||||||
/*Copyright (c) 2016, Andrew Walz.
|
/*Copyright (c) 2016, Andrew Walz.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
|
||||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class PhotoViewController: UIViewController {
|
class PhotoViewController: UIViewController {
|
||||||
|
|
||||||
override var prefersStatusBarHidden: Bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private var backgroundImage: UIImage
|
|
||||||
|
|
||||||
init(image: UIImage) {
|
|
||||||
self.backgroundImage = image
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
|
||||||
fatalError("init(coder:) has not been implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override var prefersStatusBarHidden: Bool {
|
||||||
super.viewDidLoad()
|
return true
|
||||||
self.view.backgroundColor = UIColor.gray
|
}
|
||||||
let backgroundImageView = UIImageView(frame: view.frame)
|
|
||||||
backgroundImageView.image = backgroundImage
|
private var backgroundImage: UIImage
|
||||||
view.addSubview(backgroundImageView)
|
|
||||||
let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 30.0, height: 30.0))
|
init(image: UIImage) {
|
||||||
cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControlState())
|
self.backgroundImage = image
|
||||||
cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
|
super.init(nibName: nil, bundle: nil)
|
||||||
view.addSubview(cancelButton)
|
}
|
||||||
}
|
|
||||||
|
required init?(coder aDecoder: NSCoder) {
|
||||||
func cancel() {
|
fatalError("init(coder:) has not been implemented")
|
||||||
dismiss(animated: true, completion: nil)
|
}
|
||||||
}
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
self.view.backgroundColor = UIColor.gray
|
||||||
|
let backgroundImageView = UIImageView(frame: view.frame)
|
||||||
|
backgroundImageView.contentMode = UIViewContentMode.scaleAspectFit
|
||||||
|
backgroundImageView.image = backgroundImage
|
||||||
|
view.addSubview(backgroundImageView)
|
||||||
|
let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 30.0, height: 30.0))
|
||||||
|
cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControlState())
|
||||||
|
cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
|
||||||
|
view.addSubview(cancelButton)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cancel() {
|
||||||
|
dismiss(animated: true, completion: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,127 +1,128 @@
|
||||||
/*Copyright (c) 2016, Andrew Walz.
|
/*Copyright (c) 2016, Andrew Walz.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
|
Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||||
documentation and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
|
||||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
||||||
|
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
|
|
||||||
var flipCameraButton: UIButton!
|
var flipCameraButton: UIButton!
|
||||||
var flashButton: UIButton!
|
var flashButton: UIButton!
|
||||||
var captureButton: SwiftyRecordButton!
|
var captureButton: SwiftyRecordButton!
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
cameraDelegate = self
|
cameraDelegate = self
|
||||||
maximumVideoDuration = 10.0
|
maximumVideoDuration = 10.0
|
||||||
addButtons()
|
shouldUseDeviceOrientation = true
|
||||||
}
|
addButtons()
|
||||||
|
}
|
||||||
override var prefersStatusBarHidden: Bool {
|
|
||||||
return true
|
override var prefersStatusBarHidden: Bool {
|
||||||
}
|
return true
|
||||||
|
}
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
|
||||||
super.viewDidAppear(animated)
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
}
|
super.viewDidAppear(animated)
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didTake photo: UIImage) {
|
|
||||||
let newVC = PhotoViewController(image: photo)
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didTake photo: UIImage) {
|
||||||
self.present(newVC, animated: true, completion: nil)
|
let newVC = PhotoViewController(image: photo)
|
||||||
}
|
self.present(newVC, animated: true, completion: nil)
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didBeginRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
|
|
||||||
print("Did Begin Recording")
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didBeginRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
|
||||||
captureButton.growButton()
|
print("Did Begin Recording")
|
||||||
UIView.animate(withDuration: 0.25, animations: {
|
captureButton.growButton()
|
||||||
self.flashButton.alpha = 0.0
|
UIView.animate(withDuration: 0.25, animations: {
|
||||||
self.flipCameraButton.alpha = 0.0
|
self.flashButton.alpha = 0.0
|
||||||
})
|
self.flipCameraButton.alpha = 0.0
|
||||||
}
|
})
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
|
|
||||||
print("Did finish Recording")
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishRecordingVideo camera: SwiftyCamViewController.CameraSelection) {
|
||||||
captureButton.shrinkButton()
|
print("Did finish Recording")
|
||||||
UIView.animate(withDuration: 0.25, animations: {
|
captureButton.shrinkButton()
|
||||||
self.flashButton.alpha = 1.0
|
UIView.animate(withDuration: 0.25, animations: {
|
||||||
self.flipCameraButton.alpha = 1.0
|
self.flashButton.alpha = 1.0
|
||||||
})
|
self.flipCameraButton.alpha = 1.0
|
||||||
}
|
})
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishProcessVideoAt url: URL) {
|
|
||||||
let newVC = VideoViewController(videoURL: url)
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFinishProcessVideoAt url: URL) {
|
||||||
self.present(newVC, animated: true, completion: nil)
|
let newVC = VideoViewController(videoURL: url)
|
||||||
}
|
self.present(newVC, animated: true, completion: nil)
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFocusAtPoint point: CGPoint) {
|
|
||||||
let focusView = UIImageView(image: #imageLiteral(resourceName: "focus"))
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didFocusAtPoint point: CGPoint) {
|
||||||
focusView.center = point
|
let focusView = UIImageView(image: #imageLiteral(resourceName: "focus"))
|
||||||
focusView.alpha = 0.0
|
focusView.center = point
|
||||||
view.addSubview(focusView)
|
focusView.alpha = 0.0
|
||||||
|
view.addSubview(focusView)
|
||||||
UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
|
|
||||||
focusView.alpha = 1.0
|
UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
|
||||||
focusView.transform = CGAffineTransform(scaleX: 1.25, y: 1.25)
|
focusView.alpha = 1.0
|
||||||
}, completion: { (success) in
|
focusView.transform = CGAffineTransform(scaleX: 1.25, y: 1.25)
|
||||||
UIView.animate(withDuration: 0.15, delay: 0.5, options: .curveEaseInOut, animations: {
|
}, completion: { (success) in
|
||||||
focusView.alpha = 0.0
|
UIView.animate(withDuration: 0.15, delay: 0.5, options: .curveEaseInOut, animations: {
|
||||||
focusView.transform = CGAffineTransform(translationX: 0.6, y: 0.6)
|
focusView.alpha = 0.0
|
||||||
}, completion: { (success) in
|
focusView.transform = CGAffineTransform(translationX: 0.6, y: 0.6)
|
||||||
focusView.removeFromSuperview()
|
}, completion: { (success) in
|
||||||
})
|
focusView.removeFromSuperview()
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
|
|
||||||
print(zoom)
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didChangeZoomLevel zoom: CGFloat) {
|
||||||
}
|
print(zoom)
|
||||||
|
}
|
||||||
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) {
|
|
||||||
print(camera)
|
func swiftyCam(_ swiftyCam: SwiftyCamViewController, didSwitchCameras camera: SwiftyCamViewController.CameraSelection) {
|
||||||
}
|
print(camera)
|
||||||
|
}
|
||||||
@objc private func cameraSwitchAction(_ sender: Any) {
|
|
||||||
switchCamera()
|
@objc private func cameraSwitchAction(_ sender: Any) {
|
||||||
}
|
switchCamera()
|
||||||
|
}
|
||||||
@objc private func toggleFlashAction(_ sender: Any) {
|
|
||||||
flashEnabled = !flashEnabled
|
@objc private func toggleFlashAction(_ sender: Any) {
|
||||||
|
flashEnabled = !flashEnabled
|
||||||
if flashEnabled == true {
|
|
||||||
flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControlState())
|
if flashEnabled == true {
|
||||||
} else {
|
flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControlState())
|
||||||
flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
|
} else {
|
||||||
}
|
flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private func addButtons() {
|
|
||||||
captureButton = SwiftyRecordButton(frame: CGRect(x: view.frame.midX - 37.5, y: view.frame.height - 100.0, width: 75.0, height: 75.0))
|
private func addButtons() {
|
||||||
self.view.addSubview(captureButton)
|
captureButton = SwiftyRecordButton(frame: CGRect(x: view.frame.midX - 37.5, y: view.frame.height - 100.0, width: 75.0, height: 75.0))
|
||||||
captureButton.delegate = self
|
self.view.addSubview(captureButton)
|
||||||
|
captureButton.delegate = self
|
||||||
flipCameraButton = UIButton(frame: CGRect(x: (((view.frame.width / 2 - 37.5) / 2) - 15.0), y: view.frame.height - 74.0, width: 30.0, height: 23.0))
|
|
||||||
flipCameraButton.setImage(#imageLiteral(resourceName: "flipCamera"), for: UIControlState())
|
flipCameraButton = UIButton(frame: CGRect(x: (((view.frame.width / 2 - 37.5) / 2) - 15.0), y: view.frame.height - 74.0, width: 30.0, height: 23.0))
|
||||||
flipCameraButton.addTarget(self, action: #selector(cameraSwitchAction(_:)), for: .touchUpInside)
|
flipCameraButton.setImage(#imageLiteral(resourceName: "flipCamera"), for: UIControlState())
|
||||||
self.view.addSubview(flipCameraButton)
|
flipCameraButton.addTarget(self, action: #selector(cameraSwitchAction(_:)), for: .touchUpInside)
|
||||||
|
self.view.addSubview(flipCameraButton)
|
||||||
let test = CGFloat((view.frame.width - (view.frame.width / 2 + 37.5)) + ((view.frame.width / 2) - 37.5) - 9.0)
|
|
||||||
|
let test = CGFloat((view.frame.width - (view.frame.width / 2 + 37.5)) + ((view.frame.width / 2) - 37.5) - 9.0)
|
||||||
flashButton = UIButton(frame: CGRect(x: test, y: view.frame.height - 77.5, width: 18.0, height: 30.0))
|
|
||||||
flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
|
flashButton = UIButton(frame: CGRect(x: test, y: view.frame.height - 77.5, width: 18.0, height: 30.0))
|
||||||
flashButton.addTarget(self, action: #selector(toggleFlashAction(_:)), for: .touchUpInside)
|
flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState())
|
||||||
self.view.addSubview(flashButton)
|
flashButton.addTarget(self, action: #selector(toggleFlashAction(_:)), for: .touchUpInside)
|
||||||
}
|
self.view.addSubview(flashButton)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue