How can I chain Core Animations for different Layers one after the other?

前端 未结 3 812
野的像风
野的像风 2021-02-08 15:28

I have a scrollView with paging enabled and a number N of pages, which are UIViews as subviews of the scrollView.

I\'m trying to do the following:

User scrolls t

3条回答
  •  北海茫月
    2021-02-08 15:41

    In Swift 3 (layers is an array of CALayer or CAShapeLayer)

    var timeOffset:Double = 0
    for layer in layers {
        let a = CABasicAnimation(keyPath: "path"
        a.fromValue = layer.ovalPathSmall.cgPath
        a.toValue = layer.ovalPathLarge.cgPath
        a.fillMode = kCAFillModeForwards
        a.beginTime = CACurrentMediaTime() + timeOffset
        a.duration = 0.3
        a.isRemovedOnCompletion = false
        layer.add(a, forKey: nil)
    
        timeOffset += 0.3
    }
    

    And in case you're wondering what ovalPathSmall and ovalPathLarge are:

    ovalPathSmall = UIBezierPath(arcCenter: position, radius: smallRadius, startAngle: 0, endAngle: 2 * .pi, clockwise: true)
    ovalPathLarge = UIBezierPath(arcCenter: position, radius: largeRadius, startAngle: 0, endAngle: 2 * .pi, clockwise: true)
    

提交回复
热议问题