Advent · Day 7

This one opens on December 7.

Every door opens at midnight Pacific.

See the calendar

Pattern · Media

Crop and Straighten SwiftUI Block

Crop and Straighten SwiftUI Block is a paid SwiftUI pattern in SwiftPieces Pro. Crop a photo with corner and edge handles, straighten it on a ticking dial, rotate, mirror and snap to an aspect. iOS 17.0 and later. SwiftPieces Pro is $199 once.

Crop a photo with corner and edge handles, straighten it on a ticking dial, rotate, mirror and snap to an aspect.

Buyers also search for this as a SwiftUI section.

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.

The crop tool of a photo editor as one section. The photo fills a stage, darkened outside a white frame you drag by its corners and edges or move and pinch from inside, with a thirds grid while you drag. A ruler dial straightens the photo with a haptic every five degrees, rotate and mirror sit beside it, and aspect chips keep the frame's shape.

  • SwiftUI
  • iOS 17.0+
  • photo-crop
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.

  • Corner and edge handles that keep the chosen aspect
  • A straighten dial with haptics at 0° and every 5°
  • Thirds while cropping, a finer grid while straightening
  • Rotate left, mirror and seven aspects
  • A Codable crop with a Core Image apply(to:)

Used in

Photo Editor (screen)

02

Implementation notes

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

The photo fills a stage on surface, darkened outside a white crop frame. You can drag the frame's corners, and its edges when the aspect is Free. You can also move it or pinch it from inside: pinching out zooms in. A rule-of-thirds grid appears while you drag. Under the photo, a centred readout shows the straighten angle, and Reset shows at the end of that row once anything has changed. The ruler dial below slides under a fixed accent needle. It ticks every degree, labels every five and plays a selection haptic at 0° and every 5°. It also stops softly at 0, and a double tap levels it. While you straighten, a finer 9 by 9 grid replaces the thirds, and the photo scales up so no empty corners show. Rotate left and Mirror sit either side of the dial. Under it, aspect chips (Free, Original, Square, 4:5, 3:4, 4:3 and 16:9) fit the largest frame of that shape around the current one.

Notes

  • PhotoCropBlock(image:crop:) binds a PhotoCropBlock.Crop. Pass the whole, uncropped photo with any other edits applied. Passing nil draws a grey ghost.
  • Crop is Sendable, Equatable and Codable:
    • rect: 0...1 in the straightened, quarter-turned photo.
    • angle: -45...45 degrees.
    • quarterTurns: 0...3, to the left.
    • mirrored
    • aspect
    • Crop.identity is no crop.
    • rotateLeft(), mirror() and setAspect(_:imageSize:) are the buttons' own edits.
  • crop.apply(to:) is pure Core Image and nonisolated, so render the full-resolution result off the main actor. It applies the turns, the mirror, the straighten (scaled to fill, using Crop.fillScale(angle:size:)) and then the crop.
  • While you work, the block renders only the turns and mirror (at 1600 pixels, off the main actor). The straighten and frame are drawn live on top, so dragging stays smooth.
  • VoiceOver reads the frame's size in percent. The dial is adjustable a degree at a time, and the chips mark the chosen aspect as selected. Under Reduce Motion, nothing animates between states.
  • PhotoCropBlockExample at the end of the file is the preview: the painted sample photo framed 4:5.

Theming

The block reads these tokens:

  • surface for the stage, fill for the round buttons and the loading ghost.
  • textPrimary for the readout, Reset and the chosen chip (drawn on bg).
  • textSecondary and textTertiary for the dial, separator for the other chips.
  • accent for the dial's needle.
  • radius.lg for the stage and radius.sm for the chips.
  • motion.snappy and motion.smooth.

The frame and handles are white on the photo in every family.

03

Keep building

Pieces that work well next to this one.