我已经成功使用此链接中显示的代码在 Objective-C 中为 iPhone 应用程序实现了一个可拖动按钮: http://www.cocoanetics.com/2010/11/draggable-buttons-labels/
我想知道是否存在一个可以实现动量拖动的库? 因此,如果用户移动按钮然后放开,它会继续移动一段时间,具体取决于阻力系数。
我搜索了一个库,在谷歌上搜索了“ios 按钮与动量”,但结果是空的......
最佳答案
如果您必须支持 iOS 6
当平移手势结束时,您可以以动画方式更改按钮的中心
:
if(panGestureRecognizer.state == UIGestureRecognizerStatedEnded)
{
finalVelocty.x = velocity.x;
finalyVelocity.y = velocity.y;
NSTimeInterval animationTime = 0.25; //adjust the time to your needs
[UIView animateWithDuration:0.25 animations:^{
button.center = ... // calculate button's 'final' center (depending on velocity?)
} completion:nil];
}
适用于 iOS 7 或更高版本
Apple 在 iOS 7 中引入了 UIKit Dynamics 框架(由 UIDynamicAnimator 和 UIDynamicItemBehavior 子类组成)。它是集成到 UIKit 中的物理引擎。你可以用它来达到“势头”的效果。
您可能会发现有用的示例:http://www.teehanlax.com/blog/introduction-to-uimotioneffect/
关于ios - 实现按钮拖动动量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27020010/