@@ -14,34 +14,29 @@ @interface ViewController ()
14
14
15
15
@implementation ViewController
16
16
17
- @synthesize allGesturesView;
18
- @synthesize panGestureView;
19
- @synthesize swipeGestureView;
20
- @synthesize showGestureName ;
21
- @synthesize showSubInformation ;
17
+ @synthesize allGesturesView = _allGesturesView ;
18
+ @synthesize panGestureView = _panGestureView ;
19
+ @synthesize swipeGestureView = _swipeGestureView ;
20
+ @synthesize gestureNameLabel = _gestureNameLabel ;
21
+ @synthesize subInformationLabel = _subInformationLabel ;
22
22
23
- - (void )loadView {
24
- [super loadView ];
23
+ - (void )viewDidLoad
24
+ {
25
+ [super viewDidLoad ];
25
26
26
27
// 全てのジェスチャを設定
27
- [self addTagGestureRecognizer: allGesturesView ];
28
- [self addPinchGestureRecognizer: allGesturesView ];
29
- [self addPanGestureRecognizer: allGesturesView ];
30
- [self addSwipeGestureRecognizer: allGesturesView ];
31
- [self addRotationGestureRecognizer: allGesturesView ];
32
- [self addLongPressGestureRecognizer: allGesturesView ];
28
+ [self addTagGestureRecognizer: _allGesturesView ];
29
+ [self addPinchGestureRecognizer: _allGesturesView ];
30
+ [self addPanGestureRecognizer: _allGesturesView ];
31
+ [self addSwipeGestureRecognizer: _allGesturesView ];
32
+ [self addRotationGestureRecognizer: _allGesturesView ];
33
+ [self addLongPressGestureRecognizer: _allGesturesView ];
33
34
34
35
// スワイプと同じ動作なので、ドラッグジェスチャのみを設定
35
- [self addPanGestureRecognizer: panGestureView ];
36
+ [self addPanGestureRecognizer: _panGestureView ];
36
37
37
38
// ドラッグと同じ動作なので、スワイプジェスチャのみを設定
38
- [self addSwipeGestureRecognizer: swipeGestureView];
39
- }
40
-
41
- - (void )viewDidLoad
42
- {
43
- [super viewDidLoad ];
44
- // Do any additional setup after loading the view, typically from a nib.
39
+ [self addSwipeGestureRecognizer: _swipeGestureView];
45
40
}
46
41
47
42
- (void )viewDidUnload
@@ -51,16 +46,17 @@ - (void)viewDidUnload
51
46
self.allGesturesView = nil ;
52
47
self.panGestureView = nil ;
53
48
self.swipeGestureView = nil ;
54
- self.showGestureName = nil ;
55
- self.showSubInformation = nil ;
49
+ self.gestureNameLabel = nil ;
50
+ self.subInformationLabel = nil ;
56
51
}
57
52
58
- - (void )dealloc {
59
- [allGesturesView release ];
60
- [panGestureView release ];
61
- [swipeGestureView release ];
62
- [showGestureName release ];
63
- [showSubInformation release ];
53
+ - (void )dealloc
54
+ {
55
+ [_allGesturesView release ];
56
+ [_panGestureView release ];
57
+ [_swipeGestureView release ];
58
+ [_gestureNameLabel release ];
59
+ [_subInformationLabel release ];
64
60
65
61
[super dealloc ];
66
62
}
@@ -71,7 +67,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
71
67
}
72
68
73
69
#pragma mark -
74
- #pragma mark add gestrue recognizer
70
+ #pragma mark addGestrueRecognizers
75
71
76
72
- (void )addTagGestureRecognizer : (UIView *)view
77
73
{
@@ -165,95 +161,95 @@ - (void)addLongPressGestureRecognizer:(UIView *)view
165
161
}
166
162
167
163
#pragma mark -
168
- #pragma mark touch handler
164
+ #pragma mark GestureRecognizer handlers
169
165
170
166
// 一本指でシングルタップ
171
167
- (void )handleSingleFingerSingleTap : (UITapGestureRecognizer *)recognizer {
172
- [showGestureName setText: @" UITapGestureRecognizer" ];
173
- [showSubInformation setText: @" [Single finger, Single tap]" ];
168
+ [self .gestureNameLabel setText: @" UITapGestureRecognizer" ];
169
+ [self .subInformationLabel setText: @" [Single finger, Single tap]" ];
174
170
}
175
171
176
172
// 一本指でダブルタップ
177
173
- (void )handleSingleFingerDoubleTap : (UITapGestureRecognizer *)recognizer {
178
- [showGestureName setText: @" UITapGestureRecognizer" ];
179
- [showSubInformation setText: @" [Single finger, Double tap]" ];
174
+ [self .gestureNameLabel setText: @" UITapGestureRecognizer" ];
175
+ [self .subInformationLabel setText: @" [Single finger, Double tap]" ];
180
176
}
181
177
182
178
// 二本指でシングルタップ
183
179
- (void )handleTwoFingerSingleTap : (UITapGestureRecognizer *)recognizer {
184
- [showGestureName setText: @" UITapGestureRecognizer" ];
185
- [showSubInformation setText: @" [Two finger, Single tap]" ];
180
+ [self .gestureNameLabel setText: @" UITapGestureRecognizer" ];
181
+ [self .subInformationLabel setText: @" [Two finger, Single tap]" ];
186
182
}
187
183
188
184
// 二本指でダブルタップ
189
185
- (void )handleTwoFingerDoubleTap : (UITapGestureRecognizer *)recognizer {
190
- [showGestureName setText: @" UITapGestureRecognizer" ];
191
- [showSubInformation setText: @" [Two finger, Double tap]" ];
186
+ [self .gestureNameLabel setText: @" UITapGestureRecognizer" ];
187
+ [self .subInformationLabel setText: @" [Two finger, Double tap]" ];
192
188
}
193
189
194
190
// ピンチイン・ピンチアウト
195
191
- (void )handlePinchGesture : (UIPinchGestureRecognizer *)recognizer {
196
- [showGestureName setText: @" UIPinchGestureRecognizer" ];
197
- [showSubInformation setText: [NSString stringWithFormat: @" [scale:%f , velocity:%f ]" , recognizer.scale, recognizer.velocity]];
192
+ [self .gestureNameLabel setText: @" UIPinchGestureRecognizer" ];
193
+ [self .subInformationLabel setText: [NSString stringWithFormat: @" [scale:%f , velocity:%f ]" , recognizer.scale, recognizer.velocity]];
198
194
}
199
195
200
196
// ドラッグ
201
197
- (void )handlePanGesture : (UIPanGestureRecognizer *)recognizer {
202
- [showGestureName setText: @" UIPanGestureRecognizer" ];
198
+ [self .gestureNameLabel setText: @" UIPanGestureRecognizer" ];
203
199
UIView *targetView = [recognizer view ];
204
200
CGPoint translationPoint = [recognizer translationInView: targetView];
205
201
CGPoint velocityPoint = [recognizer velocityInView: targetView];
206
- [showSubInformation setText: [NSString stringWithFormat: @" [translation:(%f ,%f ), velocity:(%f ,%f )]" , translationPoint.x, translationPoint.y, velocityPoint.x, velocityPoint.y]];
202
+ [self .subInformationLabel setText: [NSString stringWithFormat: @" [translation:(%f ,%f ), velocity:(%f ,%f )]" , translationPoint.x, translationPoint.y, velocityPoint.x, velocityPoint.y]];
207
203
}
208
204
209
205
// スワイプ
210
206
- (void )handleSwipeGesture : (UISwipeGestureRecognizer *)recognizer {
211
- [showGestureName setText: @" UISwipeGestureRecognizer" ];
212
- NSString *directionName = nil ;
207
+ [self .gestureNameLabel setText: @" UISwipeGestureRecognizer" ];
208
+ NSString *directionString = nil ;
213
209
switch ([recognizer direction ]) {
214
210
case UISwipeGestureRecognizerDirectionRight:
215
- directionName = @" UISwipeGestureRecognizerDirectionRight" ;
211
+ directionString = @" UISwipeGestureRecognizerDirectionRight" ;
216
212
break ;
217
213
case UISwipeGestureRecognizerDirectionLeft:
218
- directionName = @" UISwipeGestureRecognizerDirectionLeft" ;
214
+ directionString = @" UISwipeGestureRecognizerDirectionLeft" ;
219
215
break ;
220
216
case UISwipeGestureRecognizerDirectionUp:
221
- directionName = @" UISwipeGestureRecognizerDirectionUp" ;
217
+ directionString = @" UISwipeGestureRecognizerDirectionUp" ;
222
218
break ;
223
219
case UISwipeGestureRecognizerDirectionDown:
224
- directionName = @" UISwipeGestureRecognizerDirectionDown" ;
220
+ directionString = @" UISwipeGestureRecognizerDirectionDown" ;
225
221
break ;
226
222
}
227
- [showSubInformation setText: [NSString stringWithFormat: @" [%@ ]" , directionName ]];
223
+ [self .subInformationLabel setText: [NSString stringWithFormat: @" [%@ ]" , directionString ]];
228
224
}
229
225
230
226
// 回転
231
227
- (void )handleRotationGesture : (UIRotationGestureRecognizer *)recognizer {
232
- [showGestureName setText: @" UIRotationGestureRecognizer" ];
233
- [showSubInformation setText: [NSString stringWithFormat: @" [rotation:%f , velocity:%f ]" , recognizer.rotation, recognizer.velocity]];
228
+ [self .gestureNameLabel setText: @" UIRotationGestureRecognizer" ];
229
+ [self .subInformationLabel setText: [NSString stringWithFormat: @" [rotation:%f , velocity:%f ]" , recognizer.rotation, recognizer.velocity]];
234
230
}
235
231
236
232
// 長押し
237
233
- (void )handleLongPressGesture : (UILongPressGestureRecognizer *)recognizer {
238
- [showGestureName setText: @" UILongPressGestureRecognizer" ];
239
- NSString *actionName = nil ;
234
+ [self .gestureNameLabel setText: @" UILongPressGestureRecognizer" ];
235
+ NSString *stateString = nil ;
240
236
switch ([recognizer state ]) {
241
237
case UIGestureRecognizerStateBegan:
242
- actionName = @" UIGestureRecognizerStateBegan" ;
238
+ stateString = @" UIGestureRecognizerStateBegan" ;
243
239
break ;
244
240
case UIGestureRecognizerStateChanged:
245
- actionName = @" UIGestureRecognizerStateChanged" ;
241
+ stateString = @" UIGestureRecognizerStateChanged" ;
246
242
break ;
247
243
case UIGestureRecognizerStateEnded:
248
- actionName = @" UIGestureRecognizerStateEnd" ;
244
+ stateString = @" UIGestureRecognizerStateEnd" ;
249
245
break ;
250
246
case UIGestureRecognizerStateCancelled:
251
- actionName = @" UIGestureRecognizerStateCancelled" ;
247
+ stateString = @" UIGestureRecognizerStateCancelled" ;
252
248
break ;
253
249
default :
254
250
break ;
255
251
}
256
- [showSubInformation setText: [NSString stringWithFormat: @" [%@ ]" , actionName ]];
252
+ [self .subInformationLabel setText: [NSString stringWithFormat: @" [%@ ]" , stateString ]];
257
253
}
258
254
259
255
@end
0 commit comments