拖动手势

作者: _lijinglong | 来源:发表于2015-09-08 11:30 被阅读188次

    一、注册拖动动画

    UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self

    action:@selector(move:)];

    [self.imageView addGestureRecognizer:panGestureRecognizer];

    注:vLight就是要加入拖动的View子类。

    二、拖动处理函数

    - (void) move:(id )sender{

    UIPanGestureRecognizer *PANGETURE = sender;

    PANGETURE.view.center = CGPointMake(PANGETURE.view.center.x + movePoints.x, PANGETURE.view.center.y + movePoints.y);

    [PANGETURE setTranslation:CGPointMake(0, 0) inView:self.view];

    }

    注:最后一句为关键代码,因为拖动起来一直是在递增,所以每次都要用setTranslation:方法将每次触摸都设置为0位置,这样才不至于不受控制般滑动出视图。

    相关文章

      网友评论

        本文标题:拖动手势

        本文链接:https://www.haomeiwen.com/subject/jhtpcttx.html