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.
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.
onTapGesture()
is triggered by the user.
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.