iOS 透過 UIGestureRecognizer 提供直覺手勢操作。拖曳、旋轉與縮放常用於圖片瀏覽與互動介面。
UIPanGestureRecognizer 可取得手指位移。使用 translationInView: 取得相對位移,更新 center 後,記得呼叫 setTranslation: 歸零,避免位移累加。
UIRotationGestureRecognizer 的 rotation 代表旋轉弧度。可在既有 transform 上累加旋轉,並在每次事件後將 gesture.rotation 歸零。
UIPinchGestureRecognizer 的 scale 代表縮放比例。可在既有 transform 上縮放,並將 scale 重設為 1。若要同時支援多手勢,可實作 shouldRecognizeSimultaneouslyWithGestureRecognizer 回傳 YES。