运用iOS手势UIGestureRecognizer

// 向上擦碰
UISwipeGestureRecognizer *oneFingerSwipeUp =
  [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeUp:)] autorelease];
[oneFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[[self view] addGestureRecognizer:oneFingerSwipeUp];

- (void)oneFingerSwipeUp:(UISwipeGestureRecognizer *)recognizer
{
  CGPoint point = [recognizer locationInView:[self view]];
  NSLog(@"Swipe up - start location: %f,%f", point.x, point.y);
}

// 向下擦碰
UISwipeGestureRecognizer *oneFingerSwipeDown =
  [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeDown:)] autorelease];
[oneFingerSwipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
[[self view] addGestureRecognizer:oneFingerSwipeDown];

- (void)oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer
{
  CGPoint point = [recognizer locationInView:[self view]];
  NSLog(@"Swipe down - start location: %f,%f", point.x, point.y);
}

6、长准UILongPressGestureRecognizer对于不同种类的手势识别器,具有不同的布局属性。比如UITapGest ureRecognizer,可以安排拍击次数。界面接收到手势之后,可以发送一个音,用于拍卖应手势动作后的任务。

理所当然,不同的手势识别器,发送的音方法为会
有所不同。下面列举几单实际示范代码

UIRotationGestureRecognizer *twoFingersRotate =
  [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersRotate:)] autorelease];
[[self view] addGestureRecognizer:twoFingersRotate];

- (void)twoFingersRotate:(UIRotationGestureRecognizer *)recognizer
{
  // Convert the radian value to show the degree of rotation
  NSLog(@"Rotation in degrees since last change: %f", [recognizer rotation] * (180 / M_PI));
}

5、旋转UIRotationGestureRecognizer (手指朝相反方向走)

一个手指头,拍击两差手势

UIKit中富含了UIGestureRecognizer类,用于检测出在设施中的手势。

往里还是朝外捏的手势

使用iOS手势UIGestureRecognizer.jpg

UIKit中富含了UIGestureRecognizer类,用于检测出在设施受到之手势。UIGestureRecognizer是一个抽象类,定义了有手势的
基本表现,它来脚有子类用于拍卖具体的手势:
1、拍击UITapGestureRecognizer (任意次数之鼓掌)
2、向里或者朝向外捏UIPinchGestureRecognizer (用于缩放)
3、摇动或者拖拽UIPanGestureRecognizer 4、擦碰UISwipeGestureRecognizer
(以随机方向) 5、旋转UIRotationGestureRecognizer (手指朝相反方向动)
6、长准UILongPressGestureRecognizer对于不同门类的手势识别器,具有不同的安排属性。比如UITapGest
ureRecognizer,可以安排拍击次数。界面接收及手势之后,可以发送一个消息,用于拍卖应手势动作后的天职。当然,不同之手势识别器,发送的音方法也会见
有所不同。下面列举几个具体示例代码:http://www.ctolive.com/space-1023-do-blog-id-2107.html

// Convert the radian value to show the degree of rotation

 NSLog(@"Rotation in degrees since last change: %f", [recognizer rotation] * (180 / M_PI));

}

UIPinchGestureRecognizer *twoFingerPinch =
  [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)] autorelease];
[[self view] addGestureRecognizer:twoFingerPinch];

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
  NSLog(@"Pinch scale: %f", recognizer.scale);
}

1、拍击UITapGestureRecognizer (任意次数之鼓掌)

一个指向上、向下错碰手势

3、摇动或者拖拽UIPanGestureRecognizer

UITapGestureRecognizer *twoFingersTwoTaps =
  [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersTwoTaps)] autorelease];
[twoFingersTwoTaps setNumberOfTapsRequired:2];
[twoFingersTwoTaps setNumberOfTouchesRequired:2];
[[self view] addGestureRecognizer:twoFingersTwoTaps];

消息方法twoFingersTwoTaps
- (void)twoFingersTwoTaps {
  NSLog(@"Action: Two fingers, two taps");
} 

信方法oneFingerTwoTaps

    - (void)oneFingerTwoTaps
{
NSLog(@"Action: One finger, two taps");
    }
// 创建一个手势识别器
UITapGestureRecognizer *oneFingerTwoTaps =
  [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTwoTaps)] autorelease];

// Set required taps and number of touches
[oneFingerTwoTaps setNumberOfTapsRequired:2];
[oneFingerTwoTaps setNumberOfTouchesRequired:1];

// Add the gesture to the view
[[self view] addGestureRecognizer:oneFingerTwoTaps];

消息方法oneFingerTwoTaps
- (void)oneFingerTwoTaps
{
  NSLog(@"Action: One finger, two taps");
}

2、向里或者向外捏UIPinchGestureRecognizer (用于缩放)

些微独指头,拍击两不成手势

旋转手势

UIRotationGestureRecognizer *twoFingersRotate =
 [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersRotate:)] autorelease];
[[self view] addGestureRecognizer:twoFingersRotate];

- (void)twoFingersRotate:(UIRotationGestureRecognizer *)recognizer
{

旋转手势

// 向上擦碰

    UISwipeGestureRecognizer *oneFingerSwipeUp =
 [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeUp:)] autorelease];
    [oneFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
    [[self view] addGestureRecognizer:oneFingerSwipeUp];

- (void)oneFingerSwipeUp:(UISwipeGestureRecognizer *)recognizer
{
 CGPoint point = [recognizer locationInView:    [self view]];
  NSLog(@"Swipe up - start location: %f,%f", point.x, point.y);

}

信息方法twoFingersTwoTaps

    - (void)twoFingersTwoTaps {

NSLog(@”Action: Two fingers, two taps”);
}

// Set required taps and number of touches

    [oneFingerTwoTaps setNumberOfTapsRequired:2];
    [oneFingerTwoTaps setNumberOfTouchesRequired:1];

图片 1

4、擦碰UISwipeGestureRecognizer (以随机方向)

零星独手指头,拍击两软手势

    UITapGestureRecognizer *twoFingersTwoTaps =
 [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersTwoTaps)] autorelease];
[twoFingersTwoTaps setNumberOfTapsRequired:2];
    [twoFingersTwoTaps setNumberOfTouchesRequired:2];
[[self view] addGestureRecognizer:twoFingersTwoTaps];

一个指头向上、向下错碰手势

一个指尖,拍击两糟手势

// 创建一个手势识别器

    UITapGestureRecognizer *oneFingerTwoTaps =
    [[[UITapGestureRecognizer alloc]        initWithTarget:self action:@selector(oneFingerTwoTaps)] autorelease];

向阳里要为外捏的手势

    UIPinchGestureRecognizer *twoFingerPinch =
[[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)] autorelease];
[[self view] addGestureRecognizer:twoFingerPinch];

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
 NSLog(@"Pinch scale: %f", recognizer.scale);
}

// 向下错点

UISwipeGestureRecognizer *oneFingerSwipeDown =
 [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerSwipeDown:)] autorelease];
[oneFingerSwipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
[[self view] addGestureRecognizer:oneFingerSwipeDown];

- (void)oneFingerSwipeDown:(UISwipeGestureRecognizer *)recognizer
{
 CGPoint point = [recognizer locationInView:[self view]];
 NSLog(@"Swipe down - start location: %f,%f", point.x, point.y);

}

// Add the gesture to the view

[[self view] addGestureRecognizer:oneFingerTwoTaps];

UIGestureRecognizer是一个抽象类,定义了具备手势的 基本行为,它发脚有子类用于拍卖具体的手势:

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图