首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有弹簧效应的UIDynamicAnimator抖动

具有弹簧效应的UIDynamicAnimator抖动
EN

Stack Overflow用户
提问于 2015-07-15 16:10:48
回答 1查看 736关注 0票数 4

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

代码语言:javascript
复制
    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组合成这样的春天效应

代码语言:javascript
复制
    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在每个电话上都是一样的。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-16 15:41:51

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31435673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档