0
我有一個tableView
與panGesture
。
我可以從屏幕的底部垂直移動此tableView
。
但是,我希望panGesture
以一定的速度繼續,以在向上/向下平移時獲得scrollView類效果。分配適當的速度平移手勢iOS?
會發生什麼情況是tableView
很快向上或向下的方向移動,沒有停止的跡象。
這是我迄今所做的:
-(void)handlePanWithVelocity:(UIPanGestureRecognizer *)gestureRecognizer{
CGPoint displacement;
CGPoint velocity = [gestureRecognizer velocityInView:self.mapView];
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateBegan:{
break;
};
case UIGestureRecognizerStateChanged:{
CGPoint translation = [gestureRecognizer translationInView:self.view];
displacement = (isVerticalPan) ? CGPointMake(0, translation.y) : CGPointMake(translation.x, 0);
mytableView.transform = CGAffineTransformMakeTranslation(displacement.x, displacement.y);
break;
};
case UIGestureRecognizerStateEnded: {
displacement.y = displacement.y + velocity.y;
[UIView animateWithDuration:1 animations:^{
mytableView.transform = CGAffineTransformMakeTranslation(displacement.x, displacement.y);
}];
break;
};
case UIGestureRecognizerStatePossible:break;
case UIGestureRecognizerStateCancelled:break;
case UIGestureRecognizerStateFailed:break;
}
}
可以做些什麼來改善當前的行爲?