mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-03-25 09:05:52 +00:00
Updated Demo project
This commit is contained in:
parent
554499c09f
commit
f501ef6543
8 changed files with 182 additions and 33 deletions
|
|
@ -17,6 +17,8 @@
|
|||
1675A98E1E00A74A00B80903 /* SwiftyCamButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A98A1E00A74A00B80903 /* SwiftyCamButton.swift */; };
|
||||
1675A98F1E00A74A00B80903 /* SwiftyCamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A98B1E00A74A00B80903 /* SwiftyCamViewController.swift */; };
|
||||
1675A9901E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A98C1E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift */; };
|
||||
168505E81E288B4C005B4537 /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 168505E71E288B4C005B4537 /* VideoViewController.swift */; };
|
||||
168505EA1E288D80005B4537 /* PhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 168505E91E288D80005B4537 /* PhotoViewController.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
|
@ -32,6 +34,8 @@
|
|||
1675A98A1E00A74A00B80903 /* SwiftyCamButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftyCamButton.swift; path = ../../Source/SwiftyCamButton.swift; sourceTree = "<group>"; };
|
||||
1675A98B1E00A74A00B80903 /* SwiftyCamViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftyCamViewController.swift; path = ../../Source/SwiftyCamViewController.swift; sourceTree = "<group>"; };
|
||||
1675A98C1E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftyCamViewControllerDelegate.swift; path = ../../Source/SwiftyCamViewControllerDelegate.swift; sourceTree = "<group>"; };
|
||||
168505E71E288B4C005B4537 /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; };
|
||||
168505E91E288D80005B4537 /* PhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -68,6 +72,8 @@
|
|||
1675A9751E00A68300B80903 /* AppDelegate.swift */,
|
||||
1675A9771E00A68300B80903 /* ViewController.swift */,
|
||||
16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */,
|
||||
168505E71E288B4C005B4537 /* VideoViewController.swift */,
|
||||
168505E91E288D80005B4537 /* PhotoViewController.swift */,
|
||||
1675A9791E00A68300B80903 /* Main.storyboard */,
|
||||
1675A97C1E00A68300B80903 /* Assets.xcassets */,
|
||||
1675A97E1E00A68300B80903 /* LaunchScreen.storyboard */,
|
||||
|
|
@ -162,8 +168,10 @@
|
|||
files = (
|
||||
1675A9781E00A68300B80903 /* ViewController.swift in Sources */,
|
||||
1675A9901E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift in Sources */,
|
||||
168505E81E288B4C005B4537 /* VideoViewController.swift in Sources */,
|
||||
1675A9761E00A68300B80903 /* AppDelegate.swift in Sources */,
|
||||
1675A98F1E00A74A00B80903 /* SwiftyCamViewController.swift in Sources */,
|
||||
168505EA1E288D80005B4537 /* PhotoViewController.swift in Sources */,
|
||||
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */,
|
||||
1675A98D1E00A74A00B80903 /* PreviewView.swift in Sources */,
|
||||
1675A98E1E00A74A00B80903 /* SwiftyCamButton.swift in Sources */,
|
||||
|
|
|
|||
22
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/cancel.imageset/Contents.json
vendored
Normal file
22
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/cancel.imageset/Contents.json
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "cancel@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "cancel@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/cancel.imageset/cancel@2x.png
vendored
Normal file
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/cancel.imageset/cancel@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 701 B |
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/cancel.imageset/cancel@3x.png
vendored
Normal file
BIN
DemoSwiftyCam/DemoSwiftyCam/Assets.xcassets/cancel.imageset/cancel@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
50
DemoSwiftyCam/DemoSwiftyCam/PhotoViewController.swift
Normal file
50
DemoSwiftyCam/DemoSwiftyCam/PhotoViewController.swift
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*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:
|
||||
|
||||
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
|
||||
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,
|
||||
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
|
||||
|
||||
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() {
|
||||
super.viewDidLoad()
|
||||
self.view.backgroundColor = UIColor.gray
|
||||
let backgroundImageView = UIImageView(frame: view.frame)
|
||||
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,10 +1,17 @@
|
|||
//
|
||||
// SwiftyRecordButton.swift
|
||||
// SwiftyRecordButton
|
||||
//
|
||||
// Created by Andrew on 2017-01-11.
|
||||
// Copyright © 2017 Walzy. All rights reserved.
|
||||
//
|
||||
/*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:
|
||||
|
||||
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
|
||||
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,
|
||||
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
|
||||
|
||||
|
|
@ -38,15 +45,6 @@ class SwiftyRecordButton: SwiftyCamButton {
|
|||
}
|
||||
|
||||
public func growButton() {
|
||||
let scale = CABasicAnimation(keyPath: "transform.scale")
|
||||
scale.fromValue = 1.0
|
||||
scale.toValue = 1.20
|
||||
scale.duration = 0.3
|
||||
scale.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
|
||||
scale.fillMode = kCAFillModeForwards
|
||||
scale.isRemovedOnCompletion = false
|
||||
|
||||
|
||||
innerCircle = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||
innerCircle.center = CGPoint(x: self.bounds.midX, y: self.bounds.midY)
|
||||
innerCircle.backgroundColor = UIColor.red
|
||||
|
|
@ -54,31 +52,22 @@ class SwiftyRecordButton: SwiftyCamButton {
|
|||
innerCircle.clipsToBounds = true
|
||||
self.addSubview(innerCircle)
|
||||
|
||||
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut, animations: {
|
||||
self.innerCircle.transform = CGAffineTransform(scaleX: 50.0, y: 50.0)
|
||||
UIView.animate(withDuration: 0.6, delay: 0.0, options: .curveEaseOut, animations: {
|
||||
self.innerCircle.transform = CGAffineTransform(scaleX: 60.0, y: 60.0)
|
||||
self.circleBorder.setAffineTransform(CGAffineTransform(scaleX: 1.3, y: 1.3))
|
||||
self.circleBorder.borderWidth = (6 / 1.3)
|
||||
|
||||
}, completion: nil)
|
||||
|
||||
circleBorder.add(scale, forKey: "grow")
|
||||
}
|
||||
|
||||
public func shrinkButton() {
|
||||
let scale = CABasicAnimation(keyPath: "transform.scale")
|
||||
scale.fromValue = 1.20
|
||||
scale.toValue = 1.0
|
||||
scale.duration = 0.3
|
||||
scale.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
|
||||
scale.fillMode = kCAFillModeForwards
|
||||
scale.isRemovedOnCompletion = false
|
||||
|
||||
UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveEaseOut, animations: {
|
||||
self.innerCircle.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
||||
|
||||
self.circleBorder.setAffineTransform(CGAffineTransform(scaleX: 1.0, y: 1.0))
|
||||
self.circleBorder.borderWidth = 6.0
|
||||
}, completion: { (success) in
|
||||
self.innerCircle.removeFromSuperview()
|
||||
self.innerCircle = nil
|
||||
})
|
||||
|
||||
circleBorder.add(scale, forKey: "grow")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
78
DemoSwiftyCam/DemoSwiftyCam/VideoViewController.swift
Normal file
78
DemoSwiftyCam/DemoSwiftyCam/VideoViewController.swift
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*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:
|
||||
|
||||
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
|
||||
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,
|
||||
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
|
||||
import AVKit
|
||||
|
||||
class VideoViewController: UIViewController {
|
||||
|
||||
override var prefersStatusBarHidden: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
private var videoURL: URL
|
||||
var player: AVPlayer?
|
||||
var playerController : AVPlayerViewController?
|
||||
|
||||
init(videoURL: URL) {
|
||||
self.videoURL = videoURL
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
self.view.backgroundColor = UIColor.gray
|
||||
player = AVPlayer(url: videoURL)
|
||||
playerController = AVPlayerViewController()
|
||||
|
||||
guard player != nil && playerController != nil else {
|
||||
return
|
||||
}
|
||||
playerController!.showsPlaybackControls = false
|
||||
|
||||
playerController!.player = player!
|
||||
self.addChildViewController(playerController!)
|
||||
self.view.addSubview(playerController!.view)
|
||||
playerController!.view.frame = view.frame
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidReachEnd), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.player!.currentItem)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
player?.play()
|
||||
}
|
||||
|
||||
func cancel() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
@objc fileprivate func playerItemDidReachEnd(_ notification: Notification) {
|
||||
if self.player != nil {
|
||||
self.player!.seek(to: kCMTimeZero)
|
||||
self.player!.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,8 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
}
|
||||
|
||||
func SwiftyCamDidTakePhoto(_ photo: UIImage) {
|
||||
print(photo)
|
||||
let newVC = PhotoViewController(image: photo)
|
||||
self.present(newVC, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func SwiftyCamDidBeginRecordingVideo() {
|
||||
|
|
@ -62,7 +63,8 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
}
|
||||
|
||||
func SwiftyCamDidFinishProcessingVideoAt(_ url: URL) {
|
||||
print(url.path)
|
||||
let newVC = VideoViewController(videoURL: url)
|
||||
self.present(newVC, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func SwiftyCamDidFocusAtPoint(focusPoint: CGPoint) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue