2014-09-28 66 views
0

我想放慢由我的UIDynamicAnimator生成的動畫效果,這樣我就可以微調我的UIDynamicBehaviors。放慢UIDynamicAnimator的動畫效果

在ios模擬器中,在調試菜單下有一個菜單選項,標記爲「在最前面的應用程序中切換慢速動畫」。

但是,此選項似乎對UIDynamicAnimator生成的動畫沒有影響。有其他方法可以實現我的目標嗎?

+0

難道你不能只用更長的持續時間用於執行動畫的動畫塊(你使用animateWithDuration:....方法之一)嗎? – rdelmar 2014-09-28 17:06:10

+0

不,我沒有直接使用動畫,因爲UIDynamicAnimator爲我做了。 – benvolioT 2014-10-28 14:03:15

回答

1

您可以改變您在動畫中指定的力量,從而導致移動速度變慢。例如,你可以改變重力的大小,以加速減緩:

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)