gpt4 book ai didi

ios - UIDynamicAnimator 摇动 Spring 效果

转载 作者:搜寻专家 更新时间:2023-10-31 19:38:58 28 4
gpt4 key购买 nike

我正在尝试在此代码中替换我的核心动画摇动效果

    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 来实现 Spring 效果

    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)

问题是附件行为似乎不起作用,因为 View 在被推后不会弹回到原来的位置。动画实际上将 View 位置向右推了 100 点。 origCirclesContainerCenter 在每次调用时都是相同的。有什么想法吗?

最佳答案

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

关于ios - UIDynamicAnimator 摇动 Spring 效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31435673/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com