Skip to content

Commit 293c896

Browse files
author
UQ Times
committed
stateの状態遷移についてのコメントを分かりやすく修正
1 parent 135949f commit 293c896

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

GestureRecognizer-Samples/CustomizedGestureRecognizer/CustomizedGestureRecognizer/StrokeGestureRecognizer.m

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,16 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
153153
_strokeCount++; // ストロークの回数を増やす
154154
if ([self.wantedGesture count] < _strokeCount) {
155155
// 必要とするジェスチャーを通り過ぎた
156-
// iOS4では"Began"に設定するとずっと"Began"だが、iOS5だと1度だけ"Began"で後は自動的に"Changed"になってしまう
157-
// そのため、「Possible -> Faild / Began -> Canceled」とする
158-
if (self.state == UIGestureRecognizerStatePossible) {
159-
self.state = UIGestureRecognizerStateFailed;
160-
} else {
161-
self.state = UIGestureRecognizerStateCancelled;
162-
}
156+
// ここが実行される時には
157+
// iOS4: Began, iOS5: Began/Changed
158+
// なので、Canclledにする
159+
self.state = UIGestureRecognizerStateCancelled;
163160
return;
164161
}
165162
LocalStrokeDirection wantedDirection = [[self.wantedGesture objectAtIndex:_strokeCount - 1] intValue];
166163
if (wantedDirection != currentDirection) {
167164
// 必要とするジェスチャーではない
168-
// iOS4では"Began"に設定するとずっと"Began"だが、iOS5だと1度だけ"Began"で後は自動的に"Changed"になってしまう
169-
// そのため、「Possible -> Faild / Began -> Canceled」とする
165+
// 「Possible ならば Faild」「Began/Changed ならば Canceled」とする
170166
if (self.state == UIGestureRecognizerStatePossible) {
171167
self.state = UIGestureRecognizerStateFailed;
172168
} else {
@@ -176,9 +172,10 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
176172
}
177173
if ([self.wantedGesture count] == _strokeCount) {
178174
// 必要とするジェスチャーと一致
179-
// iOS4では"Began"に設定するとずっと"Began"だが、iOS5だと1度だけ"Began"で後は自動的に"Changed"になってしまう
180-
// iOS4:「Possible -> Began」
181-
// iOS5:「Possible -> Began -> Changed」
175+
// iOS4では"Began"に設定すると"Changed"に設定しない限りずっと"Began"だが、
176+
// iOS5では1度だけBeganで自動的に"Changed"になってしまう
177+
// iOS4: Possible -> Began -> Ended
178+
// iOS5: Possible -> Began -> Changed -> Ended
182179
self.state = UIGestureRecognizerStateBegan;
183180
return;
184181
}

0 commit comments

Comments
 (0)