Skip to content

An AVFoundation based API that allows users to access the camera and its functions on their iOS devices with SwiftUI

License

Notifications You must be signed in to change notification settings

vGebs/SwiftUICam

Repository files navigation

SwiftUICam

SwiftUICam is an AVFoundation based API that allows users to access the camera and its functions in a custom format on their iOS devices in SwiftUI with ease.

Feautures

It allows users to:

  1. Take pictures
  2. Take Videos
  3. Save pictures + videos to camera roll
  4. Toggle Between Cameras
  5. Toggle Flash
  6. Swipe to zoom

Acknowledgements

Sections of this API were derived from Awalz/SwiftyCam and KavSoft's tutorial.

Installation

This package is downloaded through Swift's Package Manager.

Usage

Using the Module

Object Initialization

import SwiftUICam

let camera = CameraWrapper()

Setting the view

  • To set the view, first create a structure that inhertits UIViewRepresentable.
  • This protocol states that you must implement two functions - MakeUIView & UpdateUIView.
  • MakeUIView - Sets the view (basically ViewDidLoad)
  • UpdateUIView - Updates after user input (viewDidChange)
  • To make these functions work with this framework, we will need to pass an instance of CameraWrapper and a view of type UIView.
  • We also want to declare the a UIView variable that will be used to specify the frame in which this view will sit.
  • Upon declaring these protocol functions and variables we can use the CameraWrapper to call the public preview setup functions as shown below.
import SwiftUICam

struct SwiftUICamPreview: UIViewRepresentable {
    
    @ObservedObject var camera: CameraWrapper
    var view: UIView

    func makeUIView(context: Context) ->  UIView {
        return camera.makeUIView(view)
    }

    func updateUIView(_ uiView: UIView, context: Context) { }
}

Further reading

For more information on how to setup/ use the interface, please reference Sources/SwiftUICam/SampleUsage

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

This package is under the MIT license

About

An AVFoundation based API that allows users to access the camera and its functions on their iOS devices with SwiftUI

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages