mirror of
https://github.com/samsonjs/SwiftyCam.git
synced 2026-03-25 09:05:52 +00:00
Added new demo button
This commit is contained in:
parent
f7b52dea9f
commit
f8376ccec6
4 changed files with 110 additions and 13 deletions
|
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */; };
|
||||
1675A9761E00A68300B80903 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A9751E00A68300B80903 /* AppDelegate.swift */; };
|
||||
1675A9781E00A68300B80903 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1675A9771E00A68300B80903 /* ViewController.swift */; };
|
||||
1675A97B1E00A68300B80903 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1675A9791E00A68300B80903 /* Main.storyboard */; };
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyRecordButton.swift; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
1675A9771E00A68300B80903 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -65,6 +67,7 @@
|
|||
1675A9911E00A74F00B80903 /* Source */,
|
||||
1675A9751E00A68300B80903 /* AppDelegate.swift */,
|
||||
1675A9771E00A68300B80903 /* ViewController.swift */,
|
||||
16298B551E2703DC0056D413 /* SwiftyRecordButton.swift */,
|
||||
1675A9791E00A68300B80903 /* Main.storyboard */,
|
||||
1675A97C1E00A68300B80903 /* Assets.xcassets */,
|
||||
1675A97E1E00A68300B80903 /* LaunchScreen.storyboard */,
|
||||
|
|
@ -161,6 +164,7 @@
|
|||
1675A9901E00A74A00B80903 /* SwiftyCamViewControllerDelegate.swift in Sources */,
|
||||
1675A9761E00A68300B80903 /* AppDelegate.swift in Sources */,
|
||||
1675A98F1E00A74A00B80903 /* SwiftyCamViewController.swift in Sources */,
|
||||
16298B561E2703DC0056D413 /* SwiftyRecordButton.swift in Sources */,
|
||||
1675A98D1E00A74A00B80903 /* PreviewView.swift in Sources */,
|
||||
1675A98E1E00A74A00B80903 /* SwiftyCamButton.swift in Sources */,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,27 +35,16 @@
|
|||
<action selector="cameraSwitchAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="a9E-90-SZM"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oLI-bi-joD" customClass="SwiftyCamButton" customModule="DemoSwiftyCam" customModuleProvider="target">
|
||||
<rect key="frame" x="152" y="577" width="70" height="70"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="70" id="lUb-f5-HQX"/>
|
||||
<constraint firstAttribute="width" constant="70" id="zFC-Ge-J3i"/>
|
||||
</constraints>
|
||||
<state key="normal" image="Camera"/>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="Bb3-ix-Jd1" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="8" symbolic="YES" id="2Fx-Ut-jDO"/>
|
||||
<constraint firstAttribute="bottom" secondItem="oLI-bi-joD" secondAttribute="bottom" constant="20" symbolic="YES" id="4S8-Ik-CMc"/>
|
||||
<constraint firstItem="oLI-bi-joD" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="7MO-81-gs9"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="SH4-0K-8ra" secondAttribute="trailing" constant="4" id="AiE-Y6-Sxj"/>
|
||||
<constraint firstItem="Bb3-ix-Jd1" firstAttribute="centerY" secondItem="SH4-0K-8ra" secondAttribute="centerY" id="Cnv-VO-rR3"/>
|
||||
<constraint firstItem="Bb3-ix-Jd1" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="4" id="yuS-xl-hcP"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="captureButton" destination="oLI-bi-joD" id="yVB-gR-PEV"/>
|
||||
<outlet property="flipCameraButton" destination="Bb3-ix-Jd1" id="Q9m-ib-9iQ"/>
|
||||
<outlet property="toggleFlashButton" destination="SH4-0K-8ra" id="BSt-X8-4Do"/>
|
||||
</connections>
|
||||
|
|
@ -65,7 +54,6 @@
|
|||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="Camera" width="70" height="70"/>
|
||||
<image name="Flash" width="30" height="19"/>
|
||||
<image name="flipCamera" width="30" height="26"/>
|
||||
</resources>
|
||||
|
|
|
|||
102
DemoSwiftyCam/DemoSwiftyCam/SwiftyRecordButton.swift
Normal file
102
DemoSwiftyCam/DemoSwiftyCam/SwiftyRecordButton.swift
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
//
|
||||
// SwiftyRecordButton.swift
|
||||
// SwiftyRecordButton
|
||||
//
|
||||
// Created by Andrew on 2017-01-11.
|
||||
// Copyright © 2017 Walzy. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class SwiftyRecordButton: SwiftyCamButton, UIGestureRecognizerDelegate {
|
||||
|
||||
private var circleBorder: CALayer!
|
||||
private var innerCircle: UIView!
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
drawButton()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
drawButton()
|
||||
}
|
||||
|
||||
private func drawButton() {
|
||||
self.backgroundColor = UIColor.clear
|
||||
|
||||
circleBorder = CALayer()
|
||||
circleBorder.backgroundColor = UIColor.clear.cgColor
|
||||
circleBorder.borderWidth = 6.0
|
||||
circleBorder.borderColor = UIColor.white.cgColor
|
||||
circleBorder.bounds = self.bounds
|
||||
circleBorder.position = CGPoint(x: self.bounds.midX, y: self.bounds.midY)
|
||||
circleBorder.cornerRadius = self.frame.size.width / 2
|
||||
layer.insertSublayer(circleBorder, at: 0)
|
||||
|
||||
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(gesture:)))
|
||||
longPress.delegate = self
|
||||
self.addGestureRecognizer(longPress)
|
||||
}
|
||||
|
||||
func handleLongPress(gesture: UILongPressGestureRecognizer){
|
||||
switch gesture.state {
|
||||
case .began:
|
||||
growButton()
|
||||
case .ended:
|
||||
shrinkButton()
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
innerCircle.layer.cornerRadius = innerCircle.frame.size.width / 2
|
||||
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)
|
||||
|
||||
}, 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)
|
||||
|
||||
}, completion: { (success) in
|
||||
self.innerCircle.removeFromSuperview()
|
||||
self.innerCircle = nil
|
||||
})
|
||||
|
||||
circleBorder.add(scale, forKey: "grow")
|
||||
}
|
||||
|
||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
|
||||
@IBOutlet weak var flipCameraButton: UIButton!
|
||||
@IBOutlet weak var toggleFlashButton: UIButton!
|
||||
@IBOutlet weak var captureButton: SwiftyCamButton!
|
||||
var captureButton: SwiftyRecordButton!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
|
@ -34,6 +34,9 @@ class ViewController: SwiftyCamViewController, SwiftyCamViewControllerDelegate {
|
|||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
captureButton = SwiftyRecordButton(frame: CGRect(x: view.frame.midX - 37.5, y: view.frame.height - 100.0, width: 75.0, height: 75.0))
|
||||
self.view.addSubview(captureButton)
|
||||
captureButton.delegate = self
|
||||
self.view.bringSubview(toFront: captureButton)
|
||||
self.view.bringSubview(toFront: flipCameraButton)
|
||||
|
|
|
|||
Loading…
Reference in a new issue