我有 calayer (+animation) 隐藏在父层后面

问题描述

我有一个隐藏在父 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")
    }
}

就这样设置

    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)

无论 ProgressLayer 实例的 zPosition 是正还是负,它都是 绘制在宿主视图的图层边框后面(圆圈的栅格化方式不同 因此,我在父级后面看到了一个“电晕”或我的动画圆圈层)

我怎样才能在宿主层支持上绘制 ProgressView ????

解决方法

我冒险走向了懦夫的道路,并重新回到了一个视图层 解决了问题的食物链上层

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...