Pinch

Pinch Pinch

A full-featured gesture focused app highlighting SwiftUI's full suite of touch gestures.

  • iOS 15+


  • SwiftUI 2.0

Concept

Pinch is a gesture focused app highlighting SwiftUI's suite of touch gestures, primarily MagnificationGesture()(pinch-to-zoom), .onTapGesture()(double-tap), .onLongPressGesture(), and the basic DragGesture(). It features two high-resolution images, which serve as the primary canvas for the utilized gesture controls, component views to provide the user with accessible controls and location information, and a sliding drawer to provide the user an unobtrusive method of changing their selected image.

Solution

As most of the app navigation relies on SwiftUI and iOS's native gestures, the design of the app requires very minimal UI. With this in mind, the primary need for a structured UI falls to accessibility for users who may be unable to perform the required two-finger gestures. The remaining UI can be limited to switching selected images, and providing the user with data related to their relative position when zoomed into the image.


With a full screen view, these accessibility controls can quickly become obtrusive, so to preserve the aesthetic of the app the non-accessibility controls are hidden by default. Similarly, the custom drawer component which houses the image selection interface is pulled off-screen by default and is moved back on screen when onTapGesture() is triggered by the user.

With the gestures and UI implemented, the remaining code serves to manage the switching of the displayed image, and the location and mangification information displayed to the user. The information is stored in the local app storage, calculated against the the center point of the image, and then displayed live to the user.

Pinch

Analysis

Pinch provided a jumping-off point for SwiftUI's gesture framework. Learning how to effectively implement tap, drag, and pinch gestures by building this app provided the necessary foundation to build more complex interactions in subsequent apps.

While the MagnificationGesture(), .onTapGesture(), and .onLongPressGesture() worked perfectly as designed, the initial DragGesture() implementation was ultimately flawed, calculating the delta from the image origin at the center, as well as in proportion to the user magnification level. This resulted in drastically exaggerated movements when attempting to navigate at greater magnifications.

An adjustment to the drag gesture implementation to factor in the magnification resulted in a drastically improved experience.