# Composing SwiftUI Gestures
[原文網站](https://developer.apple.com/documentation/swiftui/composing-swiftui-gestures)
When you add multiple gestures to your app’s view hierarchy, you need to decide how the gestures interact with each other. You use gesture composition to define the order SwiftUI recognizes gestures. There are three gesture composition types:
- gestures 手勢
- hierarchy 層次結構 (階級制度)
- decide 決定
- interact 互相作用互相影響
- each other 彼此(每個,其他)
- composition 作品 組成 (在這裡為組合)
- order 命令 順序(在這裡為順序)
- recognizes 認識識別
當你添加多個手勢到你的app頁面層次結構,你需要決定手勢彼此之間如何互相作用,你使用手勢組合去定義SwiftUI識別手勢的順序,這裡有三個手勢組成形態
-----
1. Simultaneous 同時
1. Sequenced 排序
1. Exclusive 獨家
When you combine gesture modifiers simultaneously, SwiftUI must recognize all subgesture patterns at the same time for it to recognize the combining gesture. When you sequence gesture modifiers one after the other, SwiftUI must recognize each subgesture in order. Finally, when you combine gestures exclusively, SwiftUI recognizes the entire gesture pattern when SwiftUI only recognizes one subgesture but not the others.
- combine 結合
- modifiers 修改 修飾符 (這裡是修改器)
- simultaneously 同時地
- must 必須
- recognize 認出 識別出
- subgesture 子手勢
- patterns 樣式
- same 相同
- for it 讓他 為了他
- sequence 順序
- one after the other 一個接一個
- Finally 最後
- exclusively 獨佔專門
- entire 整個 全部
- but not the others 並沒有其他
當你結合手勢的修改器(第一項 simultaneously) SwiftUI必須認出全部的子手勢樣式,同時讓他認證組合手勢。 當你一個接一個的手勢(第二項 Sequenced),SwiftUI必須照順序認出每一個子手勢,最後當你結合手勢(第三項 Exclusive),SwiftUI 認識整個手勢樣式,當SwiftUI只認識一個子手勢並沒有其他
---
### Sequence One Gesture After Another
When you sequence one gesture after another, SwiftUI recognizes the first gesture before it recognizes the second. For example, to require a long press before the user can drag a view, you sequence a DragGesture after a LongPressGesture.
- After Another 接者其他
- require 要求
- long press 長按
- `A before B` 在達成 B 之前需要先完成 A 順序 A->B
- `a after b` 在達成 A 之前需要達成 B 順序 B->A
### 排序(Sequence)一個接一個的手勢
當你排序(Sequence)一個接一個的手勢,SwiftUI識別第一個手勢在他認識力二個之前,舉例要求用戶在拖動之前需要長按,你排序拖動手勢之前加上一個長按。
---
### Model Sequenced Gesture States
To make it easier to track complicated states, use an enumeration that captures all of the states you need to configure your views. In the following example, there are three important states: no
(inactive), long press in progress (pressing), and dragging (dragging).
- easier 比較簡單(形容詞是用來修飾名詞, “Easier” 是要跟名詞一起用) easy 簡單
- track 追蹤
- complicated adj 形容詞 複雜的 難懂的
- state n 狀態
- enumeration 枚舉 (發音)
- captures 捕獲
- configure 配置
- important 重要的
- interaction 交互
- press 按下
- progress 進行中
- dragging 拖動
### 模型排序的手勢狀態
去創造他更簡單追蹤複雜的狀態,使用枚舉讓他捕捉全部狀態,你需要配置你的view,看下列的例子,他有三個重要的狀態,分別是沒互動、長按、拖動
> google
> 為了更輕鬆地跟踪複雜狀態,請使用枚舉來捕獲配置視圖所需的所有狀態。 在下面的例子中,有三個重要的狀態:無交互(inactive)、長按進行中(pressing)和拖拽(draging)。
``` swift
struct DraggableCircle: View {
enum DragState {
case inactive
case pressing
case dragging(translation: CGSize)
var translation: CGSize {
switch self {
case .inactive, .pressing:
return .zero
case .dragging(let translation):
return translation
}
}
var isActive: Bool {
switch self {
case .inactive:
return false
case .pressing, .dragging:
return true
}
}
var isDragging: Bool {
switch self {
case .inactive, .pressing:
return false
case .dragging:
return true
}
}
}
@GestureState var dragState = DragState.inactive
@State var viewState = CGSize.zero
```