我正在使用UIPanGestureRecognizer来滑动/滚动UIView。以下代码运行良好,我可以滑动/滚动panView。我的问题是,当我结束手势时,我应该使panView(UIView)像UITableView或UIScrollView滚动一样顺畅地滚动。所以请帮我解决我应该在UIGestureRecognizerStateEnded状态下编码的内容。请参考以下代码。提前致谢!!
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(scrollpanView:)];
[panRecognizer setDelegate:self];
[panView addGestureRecognizer:panRecognizer];
-(void)scrollpanView:(id)sender{
UIPanGestureRecognizer *gesture = (UIPanGestureRecognizer *)sender;
CGPoint translatedPoint = [gesture locationInView:[panView superview]].x;
if (UIGestureRecognizerStateBegan){
panXAxis = [gesture locationInView:[panView superview]].x;
translatedPoint = CGPointMake(panXAxis+translatedPoint.x, 50);
[panView setCenter:translatedPoint];
}
if ( UIGestureRecognizerStateChanged){
translatedPoint = CGPointMake(panXAxis+translatedPoint.x, 50);
[panView setCenter:translatedPoint];
}
if (UIGestureRecognizerStateEnded){
CGPoint velocity = [gesture velocityInView:[panView superview]]
// How should I scroll smoothly using the 'velocity' value
}
}