Skip to content

Commit

Permalink
Update example project.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdrobne committed Dec 8, 2022
1 parent 35c0e55 commit a206e93
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -11,15 +13,20 @@
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
2 changes: 1 addition & 1 deletion CameraButtonExample/CameraButtonExample/PhotoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct PhotoView: View {

var body: some View {
CameraButtonUI(
size: 200,
size: 72,
progressDuration: 5,
isRecording: self.$isRecording,
didFinishProgress: self.$didFinishProgress
Expand Down
59 changes: 39 additions & 20 deletions CameraButtonExample/CameraButtonExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,58 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

// setup()

let controller = UIHostingController(rootView: PhotoView())
view.addSubview(controller.view)

controller.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
controller.view.topAnchor.constraint(equalTo: view.topAnchor),
controller.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
controller.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
controller.view.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
setup()
}

// MARK: - Private methods

private func setup() {
let button = CameraButton()
button.delegate = self
let cameraButton = CameraButton()
cameraButton.delegate = self

view.addSubview(cameraButton)

cameraButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
cameraButton.widthAnchor.constraint(equalToConstant: 72),
cameraButton.heightAnchor.constraint(equalToConstant: 72),
cameraButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
cameraButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])

cameraButton.borderColor = .red
cameraButton.fillColor = (.purple, .orange)
cameraButton.progressColor = .green

let button = UIButton()
button.setTitle("CameraButtonUI", for: .normal)
button.addTarget(self, action: #selector(buttonTap), for: .touchUpInside)
view.addSubview(button)

button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
button.widthAnchor.constraint(equalToConstant: 72),
button.heightAnchor.constraint(equalToConstant: 72),
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
button.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -64)
])
}

private func cameraButtonUIController() -> UIViewController {
let controller = UIHostingController(rootView: PhotoView())
view.addSubview(controller.view)

controller.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
controller.view.topAnchor.constraint(equalTo: view.topAnchor),
controller.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
controller.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
controller.view.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])

return controller
}

button.borderColor = .red
button.fillColor = (.purple, .orange)
button.progressColor = .green
@objc func buttonTap() {
self.present(cameraButtonUIController(), animated: true)
}
}

Expand Down

0 comments on commit a206e93

Please sign in to comment.