“变换”的CAKeyframeAnimation不与CAAnimationGroup中的“不透明度”一起动画化

时间:2016-05-24 03:03:48

标签: ios core-animation calayer

CAKeyframeAnimation个对象无法在CAAnimationGroup中同时制作动画的原因是什么,但如果单独添加到CALayer会有效?

用于描述此内容的代码段:

// The following is a part of CALayer extension function

let quadAnimation = CAKeyframeAnimation(keyPath: "transform")
quadAnimation.duration = 1.0
quadAnimation.repeatCount = 1
quadAnimation.removedOnCompletion = false
quadAnimation.fillMode = kCAFillModeForwards
quadAnimation.beginTime = CACurrentMediaTime()
quadAnimation.timingFunction = CAMediaTimingFunction(controlPoints: 0.743, 0, 0.833, 0.833)

// Note:
// AGK-based methods come from a geometry manipulation library https://github.com/agens-no/AGGeometryKit
//   

var values: [NSValue] = []
let numberOfFrames = 30
for frame in 0..<numberOfFrames {
    let p = AGKEaseOutWithBezier(CGFloat(frame) / CGFloat(numberOfFrames))
    let quad = AGKQuadInterpolate(quad1, quad2, CGFloat(p))
    let innerQuad = AGKQuadMove(quad, -self.position.x, -self.position.y)
    let transform = CATransform3DWithAGKQuadFromBounds(innerQuad, CGRect(origin: CGPoint.zero, size: self.boundsSize))
    let value = NSValue(CATransform3D: transform)

    values += [value]
}

quadAnimation.values = values

let opacityAnimation = CAKeyframeAnimation(keyPath: "opacity")
opacityAnimation.keyTimes = [0, 1]
opacityAnimation.values = [0, 1]
opacityAnimation.timingFunction = CAMediaTimingFunction(controlPoints: 0.167, 0.167, 0.833, 0.833)
opacityAnimation.duration = 0.5
opacityAnimation.beginTime = CACurrentMediaTime() + 0.5
opacityAnimation.fillMode = kCAFillModeForwards

let animationBlockDelegate = AGKCALayerAnimationBlockDelegate()
animationBlockDelegate.onStart = {
    self.quadrilateral = quad2
}

let animationGroup = CAAnimationGroup()
animationGroup.animations = [quadAnimation, opacityAnimation]
animationGroup.duration = quadAnimation.duration + opacityAnimation.duration + 0.5
animationGroup.delegate = animationBlockDelegate

CATransaction.begin()
CATransaction.setCompletionBlock {
  // Completion block handler
}

self.addAnimation(animationGroup, forKey: "transformOpacityAnimationKey")

CATransaction.commit()

在权限timingFunctionbeginTime的情况下,不透明度会动画,但CA3DTransform值根本不会设置动画。

如果我将动画单独添加到图层中,以上所有工作都可以正常工作:

self.addAnimation(quadAnimation, forKey:"quadAnimation")
self.addAnimation(opacityAnimation, forKey: "opacityAnimation")

将每个动画quadAnimationopacityAnimation进程委托给AGKCALayerAnimationBlockDelegate()

0 个答案:

没有答案