0

I have an animation hidden behind the parent CALayer

import bvkit
// https://stackoverflow.com/questions/18835915/cashapelayer-animation-arc-from-0-to-final-size
class ProgressLayer: CAShapeLayer
{
    init(ellipseIn: CGRect)
    {
        super.init()
        lineWidth=4
//        let path: UIBezierPath = UIBezierPath()
//        size = ellipseIn.size
//        path.addArc(withCenter: CGPoint(x: size.width / 2, y: size.height / 2),
//                    radius: size.width / 2 - lineWidth * 2,
//                    startAngle: CGFloat(-Double.pi / 2),
//                    endAngle: CGFloat(-Double.pi / 2),
//                    clockwise: true)
        let angle = -CGFloat.pi/2
        let rotation = CGAffineTransform(rotationAngle: angle)
        let translation = CGAffineTransform(translationX: 0,y: 80)
        var concat = rotation.concatenating(translation)
        
//        let unsafe = withUnsafeMutablePointer(&rotation)
        self.path = //path.cgPath//
            CGPath(ellipseIn: ellipseIn, transform: &concat)
        lineCap = CAShapeLayerLineCap.round
        self.strokeEnd=0
    }
    // https://stackoverflow.com/questions/38468515/cabasicanimation-creates-empty-default-value-copy-of-calayer/38468678#38468678
    override init(layer: Any) {
//        if let layer = layer as? ProgressLayer {
//            // no properties to copy over just yet
//        }
        super.init(layer: layer)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func computePath(r: CGRect)
    {
        self.path = CGPath(ellipseIn: r, transform: nil)
    }
    
    func show(progress: CGFloat, duration: TimeInterval)
    {
        if self.strokeEnd>1 {
            self.strokeEnd=0
        }
        let swipe = CABasicAnimation(keyPath:"strokeEnd")
        swipe.duration = duration;
        let old = Float(strokeEnd)
        swipe.fromValue = NSNumber(value: old)
        let newEnd = progress
        swipe.toValue =  NSNumber(value: Float(newEnd))

        swipe.fillMode = CAMediaTimingFillMode.forwards;
        swipe.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        swipe.isRemovedOnCompletion=false
        self.strokeEnd = newEnd
        add(swipe, forKey: "strokeEnd animation")
    }
}

it's setup like so

    hoster.layer.cornerRadius = 40
    hoster.layer.borderWidth = 4
    hoster.layer.borderColor = UIColor.appv3BackgroundSecondaryColor.cgColor

    pl.strokeColor = UIColor.appv3MainAccentColor.cgColor
    pl.fillColor = nil
    pl.zPosition = -10
    pl.position = CGPoint(x: 40, y: 40)
        //UIColor.appv3BackgroundSecondaryColor.cgColor
    hoster.layer.addSublayer(pl)

No matter what zPosition of ProgressLayer instance is positive or negative it's drawn behind the hoster view's layer border (the circles are rasterized differently and thusly I see a "corona" or my animated circly layer behind the parent)

How could I get ProgressView draw on top of the hoster's layer backing????

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66

1 Answers1

0

I ventured towards the cowards path and have reparented to a layer of a view higher up the foodchain which have solved the problem

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
  • 1
    The other solution would be to add your layer UNDER the view's layer (using `insertSublayer(_:below:)`.) – Duncan C Apr 07 '21 at 22:59