如何提高按钮的拖动速度?

时间:2013-06-27 08:02:02

标签: ios drag-and-drop uibutton

我正在制作一个拖动代码,其中我拖动按钮,现在问题是当我开始慢慢地拖动它很酷,但是当我开始拖动它快速它不能正常工作导致按钮在拖动期间掉落。

如何提高阻力?

- (void)wasDragged:(UIButton*)button withEvent:(UIEvent*)event{
    CGPoint previousLocation;
    CGPoint location;
    UITouch *touch = [[event touchesForView:button] anyObject];
    previousLocation = [touch previousLocationInView:button];
    location = [touch locationInView:button];
    CGFloat delta_x = location.x - previousLocation.x;
    CGFloat delta_y = location.y - previousLocation.y;
    button.center = CGPointMake(button.center.x + delta_x,button.center.y + delta_y);
}

2 个答案:

答案 0 :(得分:0)

只需调整增量

即可
CGFloat delta_x = location.x - previousLocation.x;
CGFloat delta_y = location.y - previousLocation.y;

delta_x *= 1.5; //the factor of the speed
delta_y *= 1.5;

button.center = CGPointMake(button.center.x + delta_x,button.center.y + delta_y);

答案 1 :(得分:0)

为什么你不设置button.center coordonates为location.x和location.y?因为location.x和location.y是手指所在的坐标,应该有按钮的中心