Swift实现地图坐标弹跳动画

Swift 语言实现地图坐标弹跳动画的方式有两种,分别是通过UIView动画和UIDynamicAnimator动画。

对于弹跳效果,UIView动画就能满足需求,通过设置usingSpringWithDampinginitialSpringVelocity来实现弹簧效果,操作起来方便。而如果需要更精细的物理模拟,比如重力和碰撞效果,UIDynamicAnimator则更适合。

具体代码示例如下:

UIView.animateWithDuration(0.2, animations: { self.marker.layer.position.y -= 30 }, completion: { (finished) in UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 5.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { self.marker.layer.position.y += 30 }, completion: nil) })


UIView动画足够简单实用,但如果你需要更精确的物理效果,可以考虑用UIDynamicAnimator。选择合适的方法,让你的动画效果更加流畅、自然!

pdf 文件大小:67.51KB