Allow simultaneous pan and pinch gestures
WHAT IT TESTS: Simultaneous gesture recognition via the delegate. OUTLINE: Attach pan and pinch recognizers, set yourself as delegate, return true from shouldRecognizeSimultaneouslyWith, apply translation to center and scale to transform.
WHAT IT TESTS: Knowing that gesture recognizers are mutually exclusive by default and how to override that. ANSWER OUTLINE: Add a UIPanGestureRecognizer and a UIPinchGestureRecognizer to the view, set a delegate on both, and implement gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) returning true so neither blocks the other. In each handler read state, apply pan translation to center or a transform, apply pinch scale to the transform, and reset the recognizer's translation or scale to avoid compounding.
Read the original → interview
- #ios
- #uikit
- #gestures
- #uigesturerecognizer
- #transform
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.