Commit 0c05e71b by Daniel Dahan

development: added Capture video orientation change delegate method

parent 34d4b237
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Material' s.name = 'Material'
s.version = '2.3.0' s.version = '2.3.1'
s.license = 'BSD-3-Clause' s.license = 'BSD-3-Clause'
s.summary = 'Material is an animation and graphics framework that is used to create beautiful applications.' s.summary = 'Material is an animation and graphics framework that is used to create beautiful applications.'
s.homepage = 'http://materialswift.com' s.homepage = 'http://materialswift.com'
......
...@@ -221,6 +221,14 @@ public protocol CaptureDelegate { ...@@ -221,6 +221,14 @@ public protocol CaptureDelegate {
optional func capture(capture: Capture, didChangeCamera devicePosition: AVCaptureDevicePosition) optional func capture(capture: Capture, didChangeCamera devicePosition: AVCaptureDevicePosition)
/** /**
A delegation method that is executed when the device orientation changes.
- Parameter capture: A reference to the calling capture.
- Paremeter didChange videoOrientation: An AVCaptureVideoOrientation value.
*/
@objc
optional func capture(capture: Capture, didChangeFrom previousVideoOrientation: AVCaptureVideoOrientation, to videoOrientation: AVCaptureVideoOrientation)
/**
A delegation method that is executed when an image has been captured asynchronously. A delegation method that is executed when an image has been captured asynchronously.
- Parameter capture: A reference to the calling capture. - Parameter capture: A reference to the calling capture.
- Parameter asynchronouslyStill image: An image that has been captured. - Parameter asynchronouslyStill image: An image that has been captured.
...@@ -395,7 +403,7 @@ open class Capture: View { ...@@ -395,7 +403,7 @@ open class Capture: View {
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focusMode.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focusMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focusMode.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focusMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0001, userInfo: userInfo) error = NSError(domain: "com.cosmicmind.material.capture", code: 0001, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
...@@ -425,7 +433,7 @@ open class Capture: View { ...@@ -425,7 +433,7 @@ open class Capture: View {
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported flashMode.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported flashMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported flashMode.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported flashMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0002, userInfo: userInfo) error = NSError(domain: "com.cosmicmind.material.capture", code: 0002, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
...@@ -455,7 +463,7 @@ open class Capture: View { ...@@ -455,7 +463,7 @@ open class Capture: View {
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported torchMode.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported torchMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported torchMode.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported torchMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0003, userInfo: userInfo) error = NSError(domain: "com.cosmicmind.material.capture", code: 0003, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
...@@ -472,6 +480,9 @@ open class Capture: View { ...@@ -472,6 +480,9 @@ open class Capture: View {
} }
} }
/// A reference to the previous AVCaptureVideoOrientation.
open internal(set) var previousVideoOrientation: AVCaptureVideoOrientation!
/// The capture video orientation. /// The capture video orientation.
open var videoOrientation: AVCaptureVideoOrientation { open var videoOrientation: AVCaptureVideoOrientation {
var orientation: AVCaptureVideoOrientation var orientation: AVCaptureVideoOrientation
...@@ -579,6 +590,10 @@ open class Capture: View { ...@@ -579,6 +590,10 @@ open class Capture: View {
} }
} }
deinit {
removeOrientationNotifications()
}
/// A convenience initializer. /// A convenience initializer.
public convenience init() { public convenience init() {
self.init(frame: .zero) self.init(frame: .zero)
...@@ -602,12 +617,38 @@ open class Capture: View { ...@@ -602,12 +617,38 @@ open class Capture: View {
prepareImageOutput() prepareImageOutput()
prepareMovieOutput() prepareMovieOutput()
preparePreview() preparePreview()
prepareOrientationNotifications()
previousVideoOrientation = videoOrientation
isTapToFocusEnabled = true isTapToFocusEnabled = true
isTapToExposeEnabled = true isTapToExposeEnabled = true
} }
} }
extension Capture {
internal func prepareOrientationNotifications() {
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(handleOrientationNotifications(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
internal func removeOrientationNotifications() {
UIDevice.current.endGeneratingDeviceOrientationNotifications()
NotificationCenter.default.removeObserver(self)
}
/**
Handler for the captureButton.
- Parameter button: A UIButton that is associated with the event.
*/
@objc
internal func handleOrientationNotifications(_ notification: Notification) {
delegate?.capture?(capture: self, didChangeFrom: previousVideoOrientation, to: videoOrientation)
previousVideoOrientation = videoOrientation
}
}
extension Capture { extension Capture {
/// Prepares the preview. /// Prepares the preview.
internal func preparePreview() { internal func preparePreview() {
...@@ -640,7 +681,7 @@ extension Capture { ...@@ -640,7 +681,7 @@ extension Capture {
/// Prepares the sessionQueue. /// Prepares the sessionQueue.
internal func prepareSessionQueue() { internal func prepareSessionQueue() {
sessionQueue = DispatchQueue(label: "io.cosmicmind.Material.CaptureSession", attributes: .concurrent, target: nil) sessionQueue = DispatchQueue(label: "com.cosmicmind.material.capture", attributes: .concurrent, target: nil)
} }
/// Prepares the session. /// Prepares the session.
...@@ -820,7 +861,7 @@ extension Capture { ...@@ -820,7 +861,7 @@ extension Capture {
var userInfo = [String: Any]() var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focus.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focus.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focus.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focus.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0004, userInfo: userInfo) error = NSError(domain: "com.cosmicmind.material.capture", code: 0004, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
...@@ -852,7 +893,7 @@ extension Capture { ...@@ -852,7 +893,7 @@ extension Capture {
var userInfo = [String: Any]() var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported expose.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported expose.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported expose.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported expose.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0005, userInfo: userInfo) error = NSError(domain: "com.cosmicmind.material.capture", code: 0005, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
...@@ -942,14 +983,14 @@ extension Capture { ...@@ -942,14 +983,14 @@ extension Capture {
var userInfo = [String: Any]() var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot fix image orientation.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot fix image orientation.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot fix image orientation.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot fix image orientation.]"
captureError = NSError(domain: "io.cosmicmind.Material.Capture", code: 0006, userInfo: userInfo) captureError = NSError(domain: "com.cosmicmind.material.capture", code: 0006, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
} else { } else {
var userInfo = [String: Any]() var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot capture image from data.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot capture image from data.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot capture image from data.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot capture image from data.]"
captureError = NSError(domain: "io.cosmicmind.Material.Capture", code: 0007, userInfo: userInfo) captureError = NSError(domain: "com.cosmicmind.material.capture", code: 0007, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error userInfo[NSUnderlyingErrorKey] = error
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment