lonelysoul

Happy share, happy life.

导航

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];

}

 

 

祝您愉快开心 ^_^

posted on 2014-01-24 14:51  lonelysoul  阅读(335)  评论(0编辑  收藏  举报