0

我正在制作一个拖动代码,其中我正在拖动按钮,现在的问题是当我开始缓慢拖动它时它很酷,但是当我开始快速拖动它时它不能正常工作,因为在拖动过程中按钮掉落。

如何提高拖动速度?

- (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);
}
4

2 回答 2

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);
于 2013-06-27T08:23:22.413 回答
0

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

于 2013-06-27T09:52:21.447 回答