繁体   English   中英

UIDynamicAnimator具有弹簧效果

[英]UIDynamicAnimator Shake with spring effect

我试图在这段代码中替换我的核心动画抖动效果

    let shake = CAKeyframeAnimation(keyPath: "position.x")
    shake.values = [0, 20, -20, 20, -15, 15, -5, 5, 0]
    shake.keyTimes = [0, 1/10.0, 3/10.0, 5/10.0, 6/10.0, 7/10.0, 8/10.0, 9/10.0, 1]
    shake.duration = 0.4
    shake.additive = true
    circlesContainer.layer.addAnimation(shake, forKey: "shakeYourBooty")

通过结合UIPushBehaviorUIAttachmentBehavior这样的弹簧效果

    if origCirclesContainerCenter == nil {
        origCirclesContainerCenter = circlesContainer.center
    }

    shake = UIDynamicAnimator(referenceView: self.view)
    let push = UIPushBehavior(items: [circlesContainer], mode: UIPushBehaviorMode.Continuous)
    push.pushDirection = CGVectorMake(100.0, 0.0)

    print(origCirclesContainerCenter)
    let attachement = UIAttachmentBehavior(item: circlesContainer, attachedToAnchor:origCirclesContainerCenter!)
    attachement.frequency = 3.0
    attachement.damping = 0.5

    shake.addBehavior(attachement)
    shake.addBehavior(push)

问题是附件行为似乎不起作用,因为视图在被推动后不会弹回到原始位置。 动画实际上将视图位置推到右侧100点。 origCirclesContainerCenter在每次通话时都是相同的。 任何的想法?

我将推送行为模式更改为UIPushBehaviorMode.Instantaneous以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM