老是忘记 mark以下
转自:http://www.oschina.net/code/snippet_54100_8106
代码片段(5)
[代码] 一个手指,拍击两次手势
01 |
// 创建一个手势识别器 |
02 |
UITapGestureRecognizer *oneFingerTwoTaps = |
03 |
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTwoTaps)] autorelease]; |
04 |
|
05 |
// Set required taps and number of touches |
06 |
[oneFingerTwoTaps setNumberOfTapsRequired:2]; |
07 |
[oneFingerTwoTaps setNumberOfTouchesRequired:1]; |
08 |
|
09 |
// Add the gesture to the view |
10 |
[[self view] addGestureRecognizer:oneFingerTwoTaps]; |
11 |
12 |
消息方法oneFingerTwoTaps |
13 |
- ( void )oneFingerTwoTaps |
14 |
{ |
15 |
NSLog(@ "Action: One finger, two taps" ); |
16 |
} |
[代码] 两个手指,拍击两次手势
01 |
UITapGestureRecognizer *twoFingersTwoTaps = |
02 |
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersTwoTaps)] autorelease]; |
03 |
[twoFingersTwoTaps setNumberOfTapsRequired:2]; |
04 |
[twoFingersTwoTaps setNumberOfTouchesRequired:2]; |
05 |
[[self view] addGestureRecognizer:twoFingersTwoTaps]; |
06 |
07 |
消息方法twoFingersTwoTaps |
08 |
- ( void )twoFingersTwoTaps { |
09 |
NSLog(@ "Action: Two fingers, two taps" ); |
10 |
} |
[代码] 一个手指向上、向下擦碰手势
01 |
// 向上擦碰 |
02 |
UISwipeGestureRecognizer *oneFingerSwipeUp = |
03 |
[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeUp:)] autorelease]; |
04 |
[oneFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp]; |
05 |
[[self view] addGestureRecognizer:oneFingerSwipeUp]; |
06 |
07 |
- ( void )oneFingerSwipeUp:(UISwipeGestureRecognizer *)recognizer |
08 |
{ |
09 |
CGPoint point = [recognizer locationInView:[self view]]; |
10 |
NSLog(@ "Swipe up - start location: %f,%f" , point.x, point.y); |
11 |
} |
12 |
13 |
// 向下擦碰 |
14 |
UISwipeGestureRecognizer *oneFingerSwipeDown = |
15 |
[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeDown:)] autorelease]; |
16 |
[oneFingerSwipeDown setDirection:UISwipeGestureRecognizerDirectionDown]; |
17 |
[[self view] addGestureRecognizer:oneFingerSwipeDown]; |
18 |
19 |
- ( void )oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer |
20 |
{ |
21 |
CGPoint point = [recognizer locationInView:[self view]]; |
22 |
NSLog(@ "Swipe down - start location: %f,%f" , point.x, point.y); |
23 |
} |
[代码] 旋转手势
1 |
UIRotationGestureRecognizer *twoFingersRotate = |
2 |
[[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersRotate:)] autorelease]; |
3 |
[[self view] addGestureRecognizer:twoFingersRotate]; |
4 |
5 |
- ( void )twoFingersRotate:(UIRotationGestureRecognizer *)recognizer |
6 |
{ |
7 |
// Convert the radian value to show the degree of rotation |
8 |
NSLog(@ "Rotation in degrees since last change: %f" , [recognizer rotation] * (180 / M_PI)); |
9 |
} |
[代码] 向里或向外捏的手势
1 |
UIPinchGestureRecognizer *twoFingerPinch = |
2 |
[[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)] autorelease]; |
3 |
[[self view] addGestureRecognizer:twoFingerPinch]; |
4 |
5 |
- ( void )twoFingerPinch:(UIPinchGestureRecognizer *)recognizer |
6 |
{ |
7 |
NSLog(@ "Pinch scale: %f" , recognizer.scale); |
8 |
} |