手势识别器

self.view.backgroundColor = [UIColor whiteColor];

//UIGestureRecognizer  手势识别器

//手势: 有规律的触摸

//    UIGestureRecognizer 抽象类

//七种手势: 轻拍(tap) 长按(longPress) 旋转(rotation) 捏合(pinch) 拖拽(pan) 清扫(swipe) 屏幕边缘拖拽(screenEdgepan)

//图片

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

imageView.center = self.view.center;

//imageView.image = [UIImage imageNamed:@"1.jpg"];

NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"];

imageView.image = [UIImage imageWithContentsOfFile:path];

[self.view addSubview:imageView];

[imageView release];

//打开用户交互

imageView.userInteractionEnabled = YES;

#if 0

/*轻拍*/

// 创建对象

//获取到轻拍手势 让self调用tapAction:方法

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

//添加手势

[imageView addGestureRecognizer:tap];

//内存管理

[tap release];

//点击次数(默认为1)

tap.numberOfTapsRequired = 2;

//手指个数

tap.numberOfTouchesRequired = 2;

#endif

#if 0

/*长按*/

UILongPressGestureRecognizer *lp = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];

[imageView addGestureRecognizer:lp];

[lp release];

//长按时间

lp.minimumPressDuration = 1;

#endif

#if 0

/*旋转 rotation*/

UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

[imageView addGestureRecognizer:rotation];

[rotation release];

#endif

#if 0

/*捏合pinch*/

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

[imageView addGestureRecognizer:pinch];

[pinch release];

#endif

#if 0

/*清扫*/

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];

//设置方向(只支持一个方向)

swipe.direction = UISwipeGestureRecognizerDirectionRight;//向右清扫

[imageView addGestureRecognizer:swipe];

[swipe release];

#endif

#if 0

/*拖拽*/

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

[imageView addGestureRecognizer:pan];

[pan release];

#endif

#if 1

/*边缘拖拽*/

UIScreenEdgePanGestureRecognizer *edgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgePanAction:)];

//边缘平移只支持一个方向

edgePan.edges = UIRectEdgeLeft;

[imageView addGestureRecognizer:edgePan];

[edgePan release];

#endif

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • - (void)viewDidLoad { [super viewDidLoad]; // Do any addi...
    焦六金Jxx阅读 341评论 0 0
  • //七中手势:轻拍(tap) 长按(longPress) 旋转(rotation) 捏合(pinch) 拖拽(p...
    画个完美句号阅读 267评论 1 1
  • //UIGestureRecognizer 手势识别器 //七中手势:轻拍(tap) 长按(longPress)...
    肉肉要次肉阅读 208评论 0 1
  • 七种手势:轻拍(tap)、长按(longPress)、旋转(rotation)、捏合(pinch)、拖拽(pan)...
    青花_阅读 421评论 0 0
  • 昨晚和力兄通话,讨论了年度愿景规划的事情,因为很多人不知道自己要往哪里去,不知道往哪里去,就会在路上耽误太多的时间...
    虚舟老师阅读 1,314评论 8 7