我们使用手势也是比较常见的,就写一下UIGestureRecognizer的衍生类别来进行判断吧,主要是比较方便,有现成的手势,直接用就可以了,
主要有以下几种,
- UITapGestureRecognizer // 点一下
- UIPinchGestureRecognizer // 两指波动(内或者外)
- UIRotationGestureRecognizer //旋转
- UISwipeGestureRecognizer //滑动 ,快速移动
- UIPanGestureRecognizer //拖动,慢移动
- UILongPressGestureRecognizer //长按
//开启手势
-(void)SetGuesture
{
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionClick:)];
[self.myScrollerview addGestureRecognizer:recognizer];
UILongPressGestureRecognizer *Changan = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(ChangAnAction:)];
[self.myScrollerview addGestureRecognizer:Changan];
}
-(void)actionClick :(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"手势");
}
-(void)ChangAnAction:(UILongPressGestureRecognizer *)Changan
{
NSLog(@"长按");
}
当然我是写在外面的方法里,如果按照我的方法写,不要忘了在viewDidload里面调用一下这个方法哈(我想大家是不会忘记的。。仅作提醒),[danji requireGestureRecognizerToFail:shuangji];
这样就ok了,意思就是只有在双击失败的情况下,才会触发单击的方法,如此而已。