如何解决我有 calayer (+animation) 隐藏在父层后面
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 ????
解决方法
我冒险走向了懦夫的道路,并重新回到了一个视图层 解决了问题的食物链上层
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。