我正在做一个拖拽代码,我在其中拖拽按钮,现在的问题是当我开始缓慢地拖拽它时,它工作很酷,但当我开始拖拽它时,它不工作,这是因为在拖拽过程中按钮掉了。
我怎样才能提高拖拽的速度?
- (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);
}发布于 2013-06-27 16:23:22
简单地说,您只需调整增量
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-27 17:52:21
为什么不直接将button.center坐标设置为location.x和location.y?因为location.x和location.y是手指所在位置的坐标,应该是按钮的中心
https://stackoverflow.com/questions/17337784
复制相似问题