Commit b46db5a2 by Daniel Dahan

development: removed Capture, Events, and Photos

parent 6fbfcb75
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 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 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 AVFoundation
extension UIViewController {
/**
A convenience property that provides access to the CaptureController.
This is the recommended method of accessing the CaptureController
through child UIViewControllers.
*/
public var captureController: CaptureController? {
var viewController: UIViewController? = self
while nil != viewController {
if viewController is CaptureController {
return viewController as? CaptureController
}
viewController = viewController?.parent
}
return nil
}
}
open class CaptureController: ToolbarController {
/// A reference to the Capture instance.
@IBInspectable
open let capture = Capture()
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
open override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return UIInterfaceOrientation.portrait
}
open override func prepare() {
super.prepare()
displayStyle = .full
view.backgroundColor = .black
prepareStatusBar()
prepareToolbar()
prepareCapture()
}
}
extension CaptureController {
/// Prepares the statusBar.
fileprivate func prepareStatusBar() {
statusBar.backgroundColor = .clear
}
/// Prepares the toolbar.
fileprivate func prepareToolbar() {
toolbar.backgroundColor = .clear
toolbar.depthPreset = .none
}
/// Prepares capture.
fileprivate func prepareCapture() {
capture.delegate = self
capture.flashMode = .auto
}
}
extension CaptureController: CaptureDelegate {}
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 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 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 AVFoundation
open class CapturePreview: View {
open override class var layerClass: AnyClass {
return AVCaptureVideoPreviewLayer.self
}
/**
Converts a point in layer coordinates to a point of interest
in the coordinate space of the capture device providing input
to the layer.
- Parameter point: A CGPoint.
- Returns: A CGPoint that is converted.
*/
open func captureDevicePointOfInterestForPoint(point: CGPoint) -> CGPoint {
return (layer as! AVCaptureVideoPreviewLayer).captureDevicePointOfInterest(for: point)
}
/**
Converts a point of interest in the coordinate space of the
capture device providing input to the layer to a point in
layer coordinates.
- Parameter point: A CGPoint.
- Returns: A CGPoint that is converted.
*/
open func pointForCaptureDevicePointOfInterest(point: CGPoint) -> CGPoint {
return (layer as! AVCaptureVideoPreviewLayer).pointForCaptureDevicePoint(ofInterest: point)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
preparePreviewLayer()
}
/// Prepares the previewLayer.
private func preparePreviewLayer() {
layer.backgroundColor = Color.black.cgColor
layer.masksToBounds = true
(layer as! AVCaptureVideoPreviewLayer).videoGravity = AVLayerVideoGravityResizeAspectFill
}
}
...@@ -115,12 +115,20 @@ extension CollectionViewLayout { ...@@ -115,12 +115,20 @@ extension CollectionViewLayout {
offset.x += interimSpace offset.x += interimSpace
offset.y += interimSpace offset.y += interimSpace
if 0 < itemSize.width && 0 < itemSize.height { if nil != item.width {
offset.x += item.width! offset.x += item.width!
offset.y += item.height! } else if let v = item.data as? UIView, 0 < v.bounds.width {
} else if let v = item.data as? UIView {
offset.x += v.bounds.width offset.x += v.bounds.width
} else {
offset.x += itemSize.width
}
if nil != item.height {
offset.y += item.height!
} else if let v = item.data as? UIView, 0 < v.bounds.height {
offset.y += v.bounds.height offset.y += v.bounds.height
} else {
offset.y += itemSize.height
} }
} }
...@@ -148,7 +156,7 @@ extension CollectionViewLayout { ...@@ -148,7 +156,7 @@ extension CollectionViewLayout {
if let h = dataSourceItem.height { if let h = dataSourceItem.height {
attributes.frame = CGRect(x: contentEdgeInsets.left, y: offset.y, width: collectionView!.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right, height: h) attributes.frame = CGRect(x: contentEdgeInsets.left, y: offset.y, width: collectionView!.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right, height: h)
} else if let v = dataSourceItem.data as? UIView { } else if let v = dataSourceItem.data as? UIView, 0 < v.bounds.height {
v.setNeedsLayout() v.setNeedsLayout()
v.layoutIfNeeded() v.layoutIfNeeded()
...@@ -161,7 +169,7 @@ extension CollectionViewLayout { ...@@ -161,7 +169,7 @@ extension CollectionViewLayout {
if let w = dataSourceItem.width { if let w = dataSourceItem.width {
attributes.frame = CGRect(x: offset.x, y: contentEdgeInsets.top, width: w, height: collectionView!.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom) attributes.frame = CGRect(x: offset.x, y: contentEdgeInsets.top, width: w, height: collectionView!.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom)
} else if let v = dataSourceItem.data as? UIView { } else if let v = dataSourceItem.data as? UIView, 0 < v.bounds.width {
v.setNeedsLayout() v.setNeedsLayout()
v.layoutIfNeeded() v.layoutIfNeeded()
......
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 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 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
extension UIViewController {
/**
A convenience property that provides access to the EventsController.
This is the recommended method of accessing the EventsController
through child UIViewControllers.
*/
public var eventsController: EventsController? {
var viewController: UIViewController? = self
while nil != viewController {
if viewController is EventsController {
return viewController as? EventsController
}
viewController = viewController?.parent
}
return nil
}
}
open class EventsController: UIViewController {
/// A reference to an Events instance.
open let events = Events()
open override func viewDidLoad() {
super.viewDidLoad()
prepare()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open func prepare() {
view.clipsToBounds = true
view.backgroundColor = .white
view.contentScaleFactor = Screen.scale
prepareEvents()
}
}
extension EventsController {
/// Prepares the events instance.
fileprivate func prepareEvents() {
events.delegate = self
}
}
extension EventsController: EventsDelegate {}
/*
* Copyright (C) 2015 - 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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 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 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
extension UIViewController {
/**
A convenience property that provides access to the PhotoLibraryController.
This is the recommended method of accessing the PhotoLibraryController
through child UIViewControllers.
*/
public var photoLibraryController: PhotoLibraryController? {
var viewController: UIViewController? = self
while nil != viewController {
if viewController is PhotoLibraryController {
return viewController as? PhotoLibraryController
}
viewController = viewController?.parent
}
return nil
}
}
open class PhotoLibraryController: UIViewController {
/// A reference to a PhotoLibrary.
open let photoLibrary = PhotoLibrary()
open override func viewDidLoad() {
super.viewDidLoad()
prepare()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open func prepare() {
view.clipsToBounds = true
view.backgroundColor = .white
view.contentScaleFactor = Screen.scale
preparePhotoLibrary()
}
}
extension PhotoLibraryController {
/// Prepares the photoLibrary.
fileprivate func preparePhotoLibrary() {
photoLibrary.delegate = self
}
}
extension PhotoLibraryController: PhotoLibraryDelegate {}
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