From a206e9315461ddc3d89417b84446bcf27c6cd8fb Mon Sep 17 00:00:00 2001 From: Erik Drobne Date: Thu, 8 Dec 2022 15:56:30 +0100 Subject: [PATCH] Update example project. --- .../Base.lproj/LaunchScreen.storyboard | 17 ++++-- .../CameraButtonExample/PhotoView.swift | 2 +- .../CameraButtonExample/ViewController.swift | 59 ++++++++++++------- 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/CameraButtonExample/CameraButtonExample/Base.lproj/LaunchScreen.storyboard b/CameraButtonExample/CameraButtonExample/Base.lproj/LaunchScreen.storyboard index 865e932..d610b74 100644 --- a/CameraButtonExample/CameraButtonExample/Base.lproj/LaunchScreen.storyboard +++ b/CameraButtonExample/CameraButtonExample/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,10 @@ - - + + + - + + @@ -11,10 +13,10 @@ - + - + @@ -22,4 +24,9 @@ + + + + + diff --git a/CameraButtonExample/CameraButtonExample/PhotoView.swift b/CameraButtonExample/CameraButtonExample/PhotoView.swift index aea41af..061fd7f 100644 --- a/CameraButtonExample/CameraButtonExample/PhotoView.swift +++ b/CameraButtonExample/CameraButtonExample/PhotoView.swift @@ -15,7 +15,7 @@ struct PhotoView: View { var body: some View { CameraButtonUI( - size: 200, + size: 72, progressDuration: 5, isRecording: self.$isRecording, didFinishProgress: self.$didFinishProgress diff --git a/CameraButtonExample/CameraButtonExample/ViewController.swift b/CameraButtonExample/CameraButtonExample/ViewController.swift index 739685f..df4472f 100644 --- a/CameraButtonExample/CameraButtonExample/ViewController.swift +++ b/CameraButtonExample/CameraButtonExample/ViewController.swift @@ -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) } }