手势识别的 创建 与 方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手势识别的 创建 与 方法相关的知识,希望对你有一定的参考价值。
/// 手势识别器
// 1. 轻拍手势
// 手势需要在定义是绑定一个触发方法(SEL)
// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//
// // 轻拍的设置
// // 需要轻拍两次 才响应事件
// tap.numberOfTapsRequired = 2;
// // 需要几根手指 才响应事件
// tap.numberOfTouchesRequired = 2;
// // 给view添加一个手势
// [imageView addGestureRecognizer:tap];
// [tap release];
// 2. 长按手势(longPress)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
// 长按 触发方法 需要时间
longPress.minimumPressDuration = 2;
// 长按时 允许用户移动手指的距离
longPress.allowableMovement = 100;
[imageView addGestureRecognizer:longPress];
[longPress release];
// 3. 清扫手势(swipe)
// UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
// // 设置清扫方向
// swipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
//
// [imageView addGestureRecognizer:swipe];
// [swipe release];
// // 4.拖拽手势(pan)
// UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
//
// [imageView addGestureRecognizer:pan];
// [pan release];
//
//
//
//
// // 5.旋转(rotation)
// UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];
//
// [imageView addGestureRecognizer:rotation];
// [rotation release];
//
//
//
//
// // 6. 捏合手势(pinch)
// UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
//
// [imageView addGestureRecognizer:pinch];
// [pinch release];
// 7. 屏幕边缘的拖拽
UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenPan:)];
// 设置监测那一边的屏幕边缘
screenEdgePan.edges = UIRectEdgeLeft;
[imageView addGestureRecognizer:screenEdgePan];
[screenEdgePan release];
// 将UIImageView的用户交互打开,使它能响应轻拍
[imageView setUserInteractionEnabled:YES];
}
- (void)screenPan:(UIScreenEdgePanGestureRecognizer *)screenPan
{
NSLog(@"边缘拖拽");
}
// 捏合的触发方法
- (void)pinchAction:(UIPinchGestureRecognizer *)pinch
{
NSLog(@"捏合");
// 获取当前的view
UIImageView *imageView = (UIImageView *)pinch.view;
// 在x,y轴方向 放大/缩小
imageView.transform = CGAffineTransformScale(imageView.transform, pinch.scale, pinch.scale);
pinch.scale = 1; // 放大缩小的尺度(速度)
}
// 旋转方法
- (void)rotationAction:(UIRotationGestureRecognizer *)rotation
{
NSLog(@"旋转");
// 获取到当前手势添加到的view
UIImageView *imageView = (UIImageView *)rotation.view;
// 让view旋转 利用旋转手势的旋转弧度
imageView.transform = CGAffineTransformRotate(imageView.transform, rotation.rotation);
rotation.rotation = 0;
}
// 拖拽的触发方法
- (void)panAction:(UIPanGestureRecognizer *)pan
{
NSLog(@"拖拽");
// 通过手势的view属性 获取到当前手势添加到的 view
UIImageView *imageview = (UIImageView *)pan.view;
// 获取到当前手指接触的点
CGPoint p = [pan translationInView:imageview];
// 让view变形
imageview.transform = CGAffineTransformTranslate(imageview.transform,p.x, p.y);
// 重置手势的属性
[pan setTranslation:CGPointZero inView:imageview];
}
// 清扫的触发方法
- (void)swipeAction:(UISwipeGestureRecognizer *)swipe
{
NSLog(@"清扫");
}
// 轻拍的触发方法
- (void)tapAction:(UITapGestureRecognizer *)tap
{
NSLog(@"轻拍");
}
// 长按的触发方法
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan) {
NSLog(@"长按");
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
以上是关于手势识别的 创建 与 方法的主要内容,如果未能解决你的问题,请参考以下文章
如何找到intel realsense D400系列关于手势识别的详细信息?