我正在制作一个拖动代码,其中我正在拖动按钮,现在的问题是当我开始缓慢拖动它时它很酷,但是当我开始快速拖动它时它不能正常工作,因为在拖动过程中按钮掉落。
如何提高拖动速度?
- (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);
}