我试图在代码中替换我的核心动画抖动效果
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")通过将UIPushBehavior和UIAttachmentBehavior组合成这样的春天效应
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在每个电话上都是一样的。有什么想法吗?
发布于 2015-07-16 15:41:51
我将推送行为模式更改为UIPushBehaviorMode.Instantaneous以解决问题。
https://stackoverflow.com/questions/31435673
复制相似问题