iOS 六大手势

//六大手势的设置

      UIImageView *imV=(UIImageView*)[self.rv viewWithTag:101];

    //轻点

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

    tap.numberOfTapsRequired=1;//点击几次反应

    tap.numberOfTouchesRequired=1;//几个手指点击

    [imV addGestureRecognizer:tap];

    //长按

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

    lp.minimumPressDuration=2;//长按时间标准

    [imV addGestureRecognizer:lp];

    //轻扫(一次只能进行左右或者上下,不能四个方同时设置,可以做|(或)运算 )

    UISwipeGestureRecognizer *sw=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swip:)];

    sw.numberOfTouchesRequired=1;//几个手指轻扫

    sw.direction=UISwipeGestureRecognizerDirectionDown;//向下轻扫

    sw.direction=UISwipeGestureRecognizerDirectionLeft;//向左轻扫

    sw.direction=UISwipeGestureRecognizerDirectionRight;//向右轻扫

    sw.direction=UISwipeGestureRecognizerDirectionUp;//向下轻扫

    [imV addGestureRecognizer:sw];

    //拖动

    UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]

                                 initWithTarget:self action:@selector(pa:)];

    pan.minimumNumberOfTouches=1;//最小允许触控点

    pan.maximumNumberOfTouches=10;//最大允许触控点

    [imV addGestureRecognizer:pan];

    //捏合

    UIPinchGestureRecognizer *pin=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinc:)];

    [imV addGestureRecognizer:pin];

    //旋转

    UIRotationGestureRecognizer *rot=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rota:)];

    rot.rotation=2;//旋转的弧度

    [imV addGestureRecognizer:rot];

//六大手势的响应事件      

-(void)tp:(UITapGestureRecognizer*)sender1

{

    NSLog(@"轻点");

}

-(void)lop:(UILongPressGestureRecognizer*)sender2

{if(sender2.state==UIGestureRecognizerStateBegan){

    NSLog(@"长按");

}

}

-(void)swip:(UISwipeGestureRecognizer*)sender3

{

    NSLog(@"轻扫");

}

-(void)pa:(UIPanGestureRecognizer*)sender4

{

    NSLog(@"拖动");

}

-(void)pinc:(UIPinchGestureRecognizer*)sender5

{

    sender5.view.transform=CGAffineTransformMakeScale(sender5.scale, sender5.scale);

}

-(void)rota:(UIRotationGestureRecognizer*)sender6

{

    sender6.view.transform=CGAffineTransformMakeRotation(sender6.rotation);

}

      

原文地址:https://www.cnblogs.com/-ios/p/4788802.html