mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-04-27 15:07:43 +00:00
Adding merge for device orientation
This commit is contained in:
commit
e1da22fdec
6 changed files with 1194 additions and 1239 deletions
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */; };
|
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */; };
|
||||||
165CDA841E68802500FD0343 /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165CDA831E68802500FD0343 /* UIImage+Extension.swift */; };
|
|
||||||
1675A9761E00A68300B80903 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A9751E00A68300B80903 /* AppDelegate.swift */; };
|
1675A9761E00A68300B80903 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A9751E00A68300B80903 /* AppDelegate.swift */; };
|
||||||
1675A9781E00A68300B80903 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A9771E00A68300B80903 /* ViewController.swift */; };
|
1675A9781E00A68300B80903 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A9771E00A68300B80903 /* ViewController.swift */; };
|
||||||
1675A97B1E00A68300B80903 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1675A9791E00A68300B80903 /* Main.storyboard */; };
|
1675A97B1E00A68300B80903 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1675A9791E00A68300B80903 /* Main.storyboard */; };
|
||||||
|
|
@ -24,7 +23,6 @@
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyRecordButton.swift; sourceTree = "<group>"; };
|
16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyRecordButton.swift; sourceTree = "<group>"; };
|
||||||
165CDA831E68802500FD0343 /* UIImage+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Extension.swift"; sourceTree = "<group>"; };
|
|
||||||
1675A9721E00A68300B80903 /* DemoSwiftyCam.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoSwiftyCam.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
1675A9721E00A68300B80903 /* DemoSwiftyCam.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoSwiftyCam.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
1675A9751E00A68300B80903 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
1675A9751E00A68300B80903 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
1675A9771E00A68300B80903 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
1675A9771E00A68300B80903 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||||
|
|
@ -91,7 +89,6 @@
|
||||||
1675A98A1E00A74A00B80903 /* SwiftyCamButton.swift */,
|
1675A98A1E00A74A00B80903 /* SwiftyCamButton.swift */,
|
||||||
1675A98B1E00A74A00B80903 /* SwiftyCamViewController.swift */,
|
1675A98B1E00A74A00B80903 /* SwiftyCamViewController.swift */,
|
||||||
1675A98C1E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift */,
|
1675A98C1E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift */,
|
||||||
165CDA831E68802500FD0343 /* UIImage+Extension.swift */,
|
|
||||||
);
|
);
|
||||||
name = Source;
|
name = Source;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
|
@ -128,7 +125,7 @@
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
1675A9711E00A68300B80903 = {
|
1675A9711E00A68300B80903 = {
|
||||||
CreatedOnToolsVersion = 8.1;
|
CreatedOnToolsVersion = 8.1;
|
||||||
DevelopmentTeam = LW28KCU8N5;
|
DevelopmentTeam = 427VB57543;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -176,7 +173,6 @@
|
||||||
1675A98F1E00A74A00B80903 /* SwiftyCamViewController.swift in Sources */,
|
1675A98F1E00A74A00B80903 /* SwiftyCamViewController.swift in Sources */,
|
||||||
168505EA1E288D80005B4537 /* PhotoViewController.swift in Sources */,
|
168505EA1E288D80005B4537 /* PhotoViewController.swift in Sources */,
|
||||||
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */,
|
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */,
|
||||||
165CDA841E68802500FD0343 /* UIImage+Extension.swift in Sources */,
|
|
||||||
1675A98D1E00A74A00B80903 /* PreviewView.swift in Sources */,
|
1675A98D1E00A74A00B80903 /* PreviewView.swift in Sources */,
|
||||||
1675A98E1E00A74A00B80903 /* SwiftyCamButton.swift in Sources */,
|
1675A98E1E00A74A00B80903 /* SwiftyCamButton.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
|
@ -301,9 +297,9 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
DEVELOPMENT_TEAM = LW28KCU8N5;
|
DEVELOPMENT_TEAM = 427VB57543;
|
||||||
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.Cappsule.DemoSwiftyCam;
|
PRODUCT_BUNDLE_IDENTIFIER = com.Cappsule.DemoSwiftyCam;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
|
@ -315,9 +311,9 @@
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
DEVELOPMENT_TEAM = LW28KCU8N5;
|
DEVELOPMENT_TEAM = 427VB57543;
|
||||||
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
INFOPLIST_FILE = DemoSwiftyCam/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.Cappsule.DemoSwiftyCam;
|
PRODUCT_BUNDLE_IDENTIFIER = com.Cappsule.DemoSwiftyCam;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,6 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
|
||||||
<string>To record audio with videos</string>
|
|
||||||
<key>NSCameraUsageDescription</key>
|
|
||||||
<string>To take photos and videos</string>
|
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>en</string>
|
<string>en</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
|
@ -24,6 +20,10 @@
|
||||||
<string>1</string>
|
<string>1</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>To take photos and videos</string>
|
||||||
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
|
<string>To record audio with videos</string>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>LaunchScreen</string>
|
<string>LaunchScreen</string>
|
||||||
<key>UIMainStoryboardFile</key>
|
<key>UIMainStoryboardFile</key>
|
||||||
|
|
@ -35,8 +35,6 @@
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class PhotoViewController: UIViewController {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
self.view.backgroundColor = UIColor.gray
|
self.view.backgroundColor = UIColor.gray
|
||||||
let backgroundImageView = UIImageView(frame: view.frame)
|
let backgroundImageView = UIImageView(frame: view.frame)
|
||||||
|
backgroundImageView.contentMode = UIViewContentMode.scaleAspectFit
|
||||||
backgroundImageView.image = backgroundImage
|
backgroundImageView.image = backgroundImage
|
||||||
view.addSubview(backgroundImageView)
|
view.addSubview(backgroundImageView)
|
||||||
let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 30.0, height: 30.0))
|
let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 30.0, height: 30.0))
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
//
|
|
||||||
// UIImage+Extension.swift
|
|
||||||
// DemoSwiftyCam
|
|
||||||
//
|
|
||||||
// Created by Andrew on 2017-03-02.
|
|
||||||
// Copyright © 2017 Cappsule. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
import UIKit
|
|
||||||
|
|
||||||
extension UIImage {
|
|
||||||
func fixOrientation() -> UIImage? {
|
|
||||||
|
|
||||||
guard let cgImage = self.cgImage else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.imageOrientation == UIImageOrientation.up {
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
let width = self.size.width
|
|
||||||
let height = self.size.height
|
|
||||||
|
|
||||||
var transform = CGAffineTransform.identity
|
|
||||||
|
|
||||||
switch self.imageOrientation {
|
|
||||||
case .down, .downMirrored:
|
|
||||||
transform = transform.translatedBy(x: width, y: height)
|
|
||||||
transform = transform.rotated(by: CGFloat.pi)
|
|
||||||
|
|
||||||
case .left, .leftMirrored:
|
|
||||||
transform = transform.translatedBy(x: width, y: 0)
|
|
||||||
transform = transform.rotated(by: 0.5*CGFloat.pi)
|
|
||||||
|
|
||||||
case .right, .rightMirrored:
|
|
||||||
transform = transform.translatedBy(x: 0, y: height)
|
|
||||||
transform = transform.rotated(by: -0.5*CGFloat.pi)
|
|
||||||
|
|
||||||
case .up, .upMirrored:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
switch self.imageOrientation {
|
|
||||||
case .upMirrored, .downMirrored:
|
|
||||||
transform = transform.translatedBy(x: width, y: 0)
|
|
||||||
transform = transform.scaledBy(x: -1, y: 1)
|
|
||||||
|
|
||||||
case .leftMirrored, .rightMirrored:
|
|
||||||
transform = transform.translatedBy(x: height, y: 0)
|
|
||||||
transform = transform.scaledBy(x: -1, y: 1)
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we draw the underlying CGImage into a new context, applying the transform
|
|
||||||
// calculated above.
|
|
||||||
guard let colorSpace = cgImage.colorSpace else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let context = CGContext(
|
|
||||||
data: nil,
|
|
||||||
width: Int(width),
|
|
||||||
height: Int(height),
|
|
||||||
bitsPerComponent: cgImage.bitsPerComponent,
|
|
||||||
bytesPerRow: 0,
|
|
||||||
space: colorSpace,
|
|
||||||
bitmapInfo: UInt32(cgImage.bitmapInfo.rawValue)
|
|
||||||
) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
context.concatenate(transform);
|
|
||||||
|
|
||||||
switch self.imageOrientation {
|
|
||||||
|
|
||||||
case .left, .leftMirrored, .right, .rightMirrored:
|
|
||||||
// Grr...
|
|
||||||
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: height, height: width))
|
|
||||||
|
|
||||||
default:
|
|
||||||
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
|
||||||
}
|
|
||||||
|
|
||||||
// And now we just create a new UIImage from the drawing context
|
|
||||||
guard let newCGImg = context.makeImage() else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
let img = UIImage(cgImage: newCGImg)
|
|
||||||
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -26,6 +26,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
cameraDelegate = self
|
cameraDelegate = self
|
||||||
maximumVideoDuration = 10.0
|
maximumVideoDuration = 10.0
|
||||||
|
shouldUseDeviceOrientation = true
|
||||||
addButtons()
|
addButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
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
|
||||||
|
|
@ -109,6 +110,10 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
public var pinchToZoom = true
|
public var pinchToZoom = true
|
||||||
|
|
||||||
|
/// Sets the maximum zoom scale allowed during Pinch gesture
|
||||||
|
|
||||||
|
fileprivate var maxZoomScale = CGFloat(4.0)
|
||||||
|
|
||||||
/// Sets whether Tap to Focus and Tap to Adjust Exposure 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
|
public var tapToFocus = true
|
||||||
|
|
@ -131,6 +136,10 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
public var defaultCamera = CameraSelection.rear
|
public var defaultCamera = CameraSelection.rear
|
||||||
|
|
||||||
|
/// Sets wether the taken photo or video should be oriented according to the device orientation
|
||||||
|
|
||||||
|
public var shouldUseDeviceOrientation = false
|
||||||
|
|
||||||
|
|
||||||
// MARK: Public Get-only Variable Declarations
|
// MARK: Public Get-only Variable Declarations
|
||||||
|
|
||||||
|
|
@ -202,6 +211,10 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
fileprivate var flashView : UIView?
|
fileprivate var flashView : UIView?
|
||||||
|
|
||||||
|
/// Last changed orientation
|
||||||
|
|
||||||
|
fileprivate var deviceOrientation : UIDeviceOrientation?
|
||||||
|
|
||||||
/// Disable view autorotation for forced portrait recorindg
|
/// Disable view autorotation for forced portrait recorindg
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -259,6 +272,12 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
override open func viewDidAppear(_ animated: Bool) {
|
override open func viewDidAppear(_ animated: Bool) {
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
|
// Subscribe to device rotation notifications
|
||||||
|
|
||||||
|
if shouldUseDeviceOrientation {
|
||||||
|
subscribeToDeviceOrientationChangeNotifications()
|
||||||
|
}
|
||||||
|
|
||||||
// Set background audio preference
|
// Set background audio preference
|
||||||
|
|
||||||
setBackgroundAudioPreference()
|
setBackgroundAudioPreference()
|
||||||
|
|
@ -300,6 +319,11 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
|
|
||||||
//Disble flash if it is currently enabled
|
//Disble flash if it is currently enabled
|
||||||
disableFlash()
|
disableFlash()
|
||||||
|
|
||||||
|
// Unsubscribe from device rotation notifications
|
||||||
|
if shouldUseDeviceOrientation {
|
||||||
|
unsubscribeFromDeviceOrientationChangeNotifications()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Public Functions
|
// MARK: Public Functions
|
||||||
|
|
@ -372,8 +396,6 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
previewLayer.addSubview(flashView!)
|
previewLayer.addSubview(flashView!)
|
||||||
}
|
}
|
||||||
|
|
||||||
let videoPreviewLayerOrientation = previewLayer!.videoPreviewLayer.connection.videoOrientation
|
|
||||||
|
|
||||||
sessionQueue.async { [unowned self] in
|
sessionQueue.async { [unowned self] in
|
||||||
if !movieFileOutput.isRecording {
|
if !movieFileOutput.isRecording {
|
||||||
if UIDevice.current.isMultitaskingSupported {
|
if UIDevice.current.isMultitaskingSupported {
|
||||||
|
|
@ -388,7 +410,8 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
if self.currentCamera == .front {
|
if self.currentCamera == .front {
|
||||||
movieFileOutputConnection?.isVideoMirrored = true
|
movieFileOutputConnection?.isVideoMirrored = true
|
||||||
}
|
}
|
||||||
movieFileOutputConnection?.videoOrientation = videoPreviewLayerOrientation
|
|
||||||
|
movieFileOutputConnection?.videoOrientation = self.getVideoOrientation()
|
||||||
|
|
||||||
// Start recording to a temporary file.
|
// Start recording to a temporary file.
|
||||||
let outputFileName = UUID().uuidString
|
let outputFileName = UUID().uuidString
|
||||||
|
|
@ -636,6 +659,54 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Orientation management
|
||||||
|
|
||||||
|
fileprivate func subscribeToDeviceOrientationChangeNotifications() {
|
||||||
|
self.deviceOrientation = UIDevice.current.orientation
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func unsubscribeFromDeviceOrientationChangeNotifications() {
|
||||||
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
|
||||||
|
self.deviceOrientation = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc fileprivate func deviceDidRotate() {
|
||||||
|
if !UIDevice.current.orientation.isFlat {
|
||||||
|
self.deviceOrientation = UIDevice.current.orientation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func getVideoOrientation() -> AVCaptureVideoOrientation {
|
||||||
|
guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else { return previewLayer!.videoPreviewLayer.connection.videoOrientation }
|
||||||
|
|
||||||
|
switch deviceOrientation {
|
||||||
|
case .landscapeLeft:
|
||||||
|
return .landscapeRight
|
||||||
|
case .landscapeRight:
|
||||||
|
return .landscapeLeft
|
||||||
|
case .portraitUpsideDown:
|
||||||
|
return .portraitUpsideDown
|
||||||
|
default:
|
||||||
|
return .portrait
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func getImageOrientation(forCamera: CameraSelection) -> UIImageOrientation {
|
||||||
|
guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else { return forCamera == .rear ? .right : .leftMirrored }
|
||||||
|
|
||||||
|
switch deviceOrientation {
|
||||||
|
case .landscapeLeft:
|
||||||
|
return forCamera == .rear ? .up : .downMirrored
|
||||||
|
case .landscapeRight:
|
||||||
|
return forCamera == .rear ? .down : .upMirrored
|
||||||
|
case .portraitUpsideDown:
|
||||||
|
return forCamera == .rear ? .left : .rightMirrored
|
||||||
|
default:
|
||||||
|
return forCamera == .rear ? .right : .leftMirrored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a UIImage from Image Data.
|
Returns a UIImage from Image Data.
|
||||||
|
|
||||||
|
|
@ -648,33 +719,17 @@ open class SwiftyCamViewController: UIViewController {
|
||||||
let dataProvider = CGDataProvider(data: imageData as CFData)
|
let dataProvider = CGDataProvider(data: imageData as CFData)
|
||||||
let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent)
|
let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent)
|
||||||
|
|
||||||
var image: UIImage!
|
|
||||||
|
|
||||||
// Set proper orientation for photo
|
// Set proper orientation for photo
|
||||||
// If camera is currently set to front camera, flip image
|
// If camera is currently set to front camera, flip image
|
||||||
|
|
||||||
switch self.currentCamera {
|
let image = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: self.getImageOrientation(forCamera: self.currentCamera))
|
||||||
case .front:
|
|
||||||
let newImage = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: .leftMirrored)
|
|
||||||
if let adjustedImage = newImage.fixOrientation() {
|
|
||||||
image = adjustedImage
|
|
||||||
} else {
|
|
||||||
image = newImage
|
|
||||||
}
|
|
||||||
case .rear:
|
|
||||||
let newImage = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: .right)
|
|
||||||
if let adjustedImage = newImage.fixOrientation() {
|
|
||||||
image = adjustedImage
|
|
||||||
} else {
|
|
||||||
image = newImage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return image
|
return image
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func capturePhotoAsyncronously(completionHandler: @escaping(Bool) -> ()) {
|
fileprivate func capturePhotoAsyncronously(completionHandler: @escaping(Bool) -> ()) {
|
||||||
if let videoConnection = photoFileOutput?.connection(withMediaType: AVMediaTypeVideo) {
|
if let videoConnection = photoFileOutput?.connection(withMediaType: AVMediaTypeVideo) {
|
||||||
videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
|
|
||||||
photoFileOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
|
photoFileOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
|
||||||
if (sampleBuffer != nil) {
|
if (sampleBuffer != nil) {
|
||||||
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
|
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
|
||||||
|
|
@ -908,7 +963,7 @@ extension SwiftyCamViewController {
|
||||||
let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
|
let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
|
||||||
try captureDevice?.lockForConfiguration()
|
try captureDevice?.lockForConfiguration()
|
||||||
|
|
||||||
zoomScale = max(1.0, min(beginZoomScale * pinch.scale, captureDevice!.activeFormat.videoMaxZoomFactor))
|
zoomScale = min(maxZoomScale, max(1.0, min(beginZoomScale * pinch.scale, captureDevice!.activeFormat.videoMaxZoomFactor)))
|
||||||
|
|
||||||
captureDevice?.videoZoomFactor = zoomScale
|
captureDevice?.videoZoomFactor = zoomScale
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue