首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何提高按钮的拖拽速度?

如何提高按钮的拖拽速度?
EN

Stack Overflow用户
提问于 2013-06-27 16:02:02
回答 2查看 103关注 0票数 0

我正在做一个拖拽代码,我在其中拖拽按钮,现在的问题是当我开始缓慢地拖拽它时,它工作很酷,但当我开始拖拽它时,它不工作,这是因为在拖拽过程中按钮掉了。

我怎样才能提高拖拽的速度?

代码语言:javascript
复制
- (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);
}
EN

回答 2

Stack Overflow用户

发布于 2013-06-27 16:23:22

简单地说,您只需调整增量

代码语言:javascript
复制
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);
票数 0
EN

Stack Overflow用户

发布于 2013-06-27 17:52:21

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17337784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档