Advent · Day 2

This one opens on December 2.

Every door opens at midnight Pacific.

See the calendar

Screen · Media

SwiftUI Camera Screen with AVFoundation

SwiftUI Camera Screen with AVFoundation is a paid SwiftUI screen in SwiftPieces Pro. A full camera on AVFoundation: real lens buttons, tap to focus with an exposure sun, timer, Photo, Square and Video, and review. iOS 17.0 and later. SwiftPieces Pro is $199 once.

A full camera on AVFoundation: real lens buttons, tap to focus with an exposure sun, timer, Photo, Square and Video, and review.

Buyers also search for this as a iOS screen.

Facts
Price$199 once
iOSiOS 17.0 and later
LicenseA per-developer commercial license for unlimited personal and commercial apps, including client work. Do not resell or redistribute the source as a template or UI kit.
DependenciesNo third-party packages. Apple frameworks only.
Files1 Swift file in the install.

A complete capture screen around a 3:4 viewfinder with a thirds grid. Lens buttons follow the phone's real cameras with pinch to zoom between them, a tap focuses and meters with an exposure sun you drag, and a long press locks both. Flash, a 3 or 10 second timer, Photo, Square and Video modes, a shutter that blinks the frame, the last shot as a thumbnail and a review with Use Photo cover the rest, with designed states for a declined or missing camera.

  • SwiftUI
  • iOS 17.0+
  • camera
Get SwiftPieces Pro

$199 once, every piece included. See how installing works · Sign in

Proof

This targets iOS 17.0 and later. On iOS 26 it uses Liquid Glass. On iOS 17 through iOS 18 it uses a material fallback, including when Reduce Transparency is on.

No simulator still is published for this page yet.

01

What's included

SwiftUI source you own, built on Apple frameworks only.

  • Lens buttons from the phone's real cameras, with pinch to zoom
  • Tap to focus, drag the exposure sun, hold to lock AE/AF
  • Photo, Square and Video with a recording clock and torch
  • Flash, a 3 or 10 second timer and a thirds grid
  • Review with Use Photo, plus declined and no-camera states

02

Implementation notes

How it behaves, what it handles, and the decisions behind it.

A capture screen built on AVFoundation. The top bar has close, flash (auto, on or off), the frame's shape, a 3 or 10 second timer and the thirds grid. Under it is a 3:4 viewfinder. Its lens buttons come from the phone's real cameras: 0.5 when there is an ultra wide, 1, 2 and the telephoto's own number. You can also pinch to zoom between them, and the chosen lens shows the live zoom, such as 1.4×. A tap focuses and meters at that point and shows a focus square with an exposure sun beside it. Drag up or down to brighten or darken. Press and hold, then lift, to lock focus and exposure, and an AE/AF Lock tag appears. Otherwise focus returns to continuous when the scene changes. The mode strip switches between Video, Photo and Square. Square masks the frame and crops the photo. In Video, the shutter turns red, recording shows a running clock in the top bar, and flash on lights the torch. Taking a photo blinks the frame and drops the shot into the thumbnail, and the thumbnail opens a review with Retake and Use Photo or Use Video. A declined camera shows a designed message with Open Settings. A phone with no usable camera shows its own message.

Notes

  • CameraScreen(modes:initialMode:reviewsEachCapture:demoImage:onUse:onClose:). Present it with fullScreenCover. modes sets the strip, in order. reviewsEachCapture opens the review after every shot, as a profile photo flow does. Without it, shots collect behind the thumbnail.
  • onUse is @MainActor async throws and receives a CameraScreen.Capture. The Use button shows working while it runs. A thrown error appears under the button. Throwing CancellationError returns quietly.
  • CameraScreen.Capture has a kind (photo or video), data (HEIF where the device supports it, otherwise JPEG; square in Square mode), fileURL for a video (a .mov in the temporary directory, deleted on Retake), the date, a small thumbnail and image for the full photo.
  • demoImage is shown in the viewfinder, and captured, when the device has no camera, such as the Simulator or a Mac. This lets you build and test the rest of your flow there. Video needs a real camera.
  • The session lives on its own serial queue. The screen starts it when it appears and stops it when it disappears. Photos use AVCapturePhotoOutput at the photo preset. Video adds AVCaptureMovieFileOutput and the microphone only while Video is chosen, so photos keep full resolution. Captures are upright for a portrait screen.
  • Permission: the screen asks for the camera the first time it opens, and for the microphone the first time Video is chosen. If the microphone is declined, videos record without sound.
  • Haptics play for each shot, each mode change and each second of the timer. Under Reduce Motion the lens and shutter changes don't animate.
  • VoiceOver reads every button by what it does, such as "Zoom 2 times", "Take photo", "Stop recording" and "Flash auto", and marks the chosen mode and lens as selected.
  • CameraScreenExample at the end of CameraScreen.swift is the screen in the preview, in Studio, on a painted landscape (CameraScreenSample.landscape), with an onUse that waits a moment and succeeds.

Theming

The chrome is black in every family, as a camera's should be. The chosen mode is white and semibold. The screen reads accent for the Use and Open Settings buttons, accentOn for their labels, danger for a failure line, the theme's type roles (subhead, caption, headline, title3, footnote, body) and numeral for the countdown and recording clock, and motion.snappy for the lens and shutter changes.

Requirements

  • NSCameraUsageDescription in Info.plist.
  • NSMicrophoneUsageDescription when the modes include Video.