Swiftpack.co - erikdrobne/CameraButton as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by erikdrobne.
erikdrobne/CameraButton 2.0.0
A simple camera button that can be used for photo and video capturing.
⭐️ 20
🕓 1 year ago
iOS
.package(url: "https://github.com/erikdrobne/CameraButton.git", from: "2.0.0")

CameraButton

RPReplay_Final1642669292 RPReplay_Final1642670033

A simple camera button that can be used for photo and video capturing.

Requirements

iOS 14.0 or higher

Instalation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/erikdrobne/CameraButton")
]

Usage

Import

import CameraButton

UIKit

Initialize

let button = CameraButton()
button.delegate = self
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.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -64)
])

Customize

// Set custom colors
button.borderColor = .red
button.fillColor = (.purple, .orange)
button.progressColor = .green

// Set progress animation duration
button.progressDuration = 5

// Start progress animation
button.start()

// Stop progress animation
button.stop()

Delegate

The CameraButtonDelegate requires you to implement the following methods:

func didTap(_ button: CameraButton)
func didFinishProgress()

SwiftUI

struct PhotoView: View {

    @State var isRecording: Bool = false
    @State var didFinishProgress: Bool = false

    var body: some View {
        CameraButtonUI(
            size: 72,
            borderColor: .red,
            fillColor: (.purple, .orange),
            progressColor: .green,
            progressDuration: 5,
            isRecording: self.$isRecording
        )
        // Handle tap gesture
        .simultaneousGesture(
            TapGesture()
                .onEnded { _ in
                    print("tap")
                }
        )
        // Start recording on Long-press gesture
        .gesture(
            LongPressGesture(minimumDuration: 1)
                .onChanged { val in
                    isRecording = true
                }
        )
        // Observe state changes
        .onChange(of: isRecording, perform: { [isRecording] newValue in
            print("isRecording", isRecording, newValue)
        })
    }
}

GitHub

link
Stars: 20
Last commit: 33 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

2.0.0
1 year ago
  • Add SwiftUI support
  • Update documentation

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics