0

我想减慢我的 UIDynamicAnimator 生成的动画,以便我可以微调我的 UIDynamicBehaviors。

在 ios 模拟器中,Debug 菜单下有一个菜单选项,标签为“Toggle slow animations in frontmost app”。

但是,这个选项似乎对 UIDynamicAnimator 生成的动画没有影响。还有其他方法可以实现我的目标吗?

4

1 回答 1

2

您可以更改您在动画中指定的力以降低运动速度。例如,您可以更改重力大小以减慢加速度:

    self.animator = UIDynamicAnimator(referenceView: self.view)
    var gravity = UIGravityBehavior(items: [animatedView])
    gravity.magnitude = 0.5

如果发生碰撞,您也可能会增加摩擦力和/或弹性以减慢速度,尽管在某些情况下这可能会影响轨迹:

    let bounceProperties = UIDynamicItemBehavior(items: [animatedView])
    bounceProperties.elasticity = 0.5
    bounceProperties.friction = 0.2

    var collision = UICollisionBehavior(items: [animatedView])
    var boundaryId: NSMutableString = NSMutableString(string: "bottomBoundary")
    let boundaryPath = UIBezierPath(rect: boundaryFrame)
    collision.addBoundaryWithIdentifier(boundaryId, forPath: boundaryPath)

    // Start animating
    animator.addBehavior(gravity)
    animator.addBehavior(collision)
    animator.addBehavior(bounceProperties)
于 2015-02-09T08:40:34.827 回答