我已经成功使用此链接上显示的代码在Objective-C中为iPhone应用程序实现了可拖动按钮:http : //www.cocoanetics.com/2010/11/draggable-buttons-labels/
我想知道是否有一个图书馆能够实现这种拖累?因此,如果用户先移动按钮然后放开,则它将根据拖动系数继续移动一会儿。
我搜索了一个图书馆,用Google搜索“带动量的ios按钮”,但是却空了...
如果您必须支持iOS 6
center
当平移手势结束时,您可以为按钮的变化设置动画:
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或更高版本
苹果在iOS 7中引入了UIKit Dynamics框架(由UIDynamicAnimator和UIDynamicItemBehavior子类组成)。它是UIKit中集成的物理引擎。您可以使用它来实现“动量”效果。
您可能会发现有用的示例:http : //www.teehanlax.com/blog/introduction-to-uimotioneffect/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句