拖动手势实现代码


- (void)awakeFromNib

{

    //    添加手势

    UIPanGestureRecognizer *panPG = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPg:)];

    

    [self addGestureRecognizer:panPG];

    

    

}

// 拖拽手势业务逻辑

- (void)panPg:(UIPanGestureRecognizer *)panPg

{

    CGPoint panP = [panPg translationInView:self];

    

    self.transform = CGAffineTransformTranslate(self.transform, panP.x, 0);

    

    //    复位

    [panPg setTranslation:CGPointZero inView:self];

    

    

}

你可能感兴趣的:(拖动手势实现代码)