UIPanGestureRecognizer下方法

- (IBAction)handlePan:(UIPanGestureRecognizer *)sender

{

    // translationInView: 滑动的偏移量

    CGPoint point = [sender translationInView:self.view];

    // locationInView: 手势在self.view中的位置 // 此方法属于UIGestureRecognizer

    CGPoint point1 = [sender locationInView:self.view];

    NSLog(@"translation:%@ location:%@",NSStringFromCGPoint(point), NSStringFromCGPoint(point1));

    sender.view.center = CGPointMake(sender.view.center.x + point.x,

                                     sender.view.center.y + point.y);

    // 这句话非常重要,拖动的时候是一直递增的,每次都得清零才不至于出视图外面

    [sender setTranslation:CGPointZeroinView:self.view];

}

 

 

祝您愉快开心 ^_^

原文地址:https://www.cnblogs.com/tianglin/p/3532447.html