我需要通过所有文本层将透明弧从0切换到pi。 除了一件事之外,代码在上面工作正常。 我在执行CABasicAnimation屏蔽CALayer时没有小宽度线,在空闲状态下没有奇怪的行。
无法理解为什么它会显示,因为理论上它根本不可见......
这是我的游乐场代码:
import UIKit
import PlaygroundSupport
let rootView = UIView(frame: CGRect(x: 0, y: 0,
width: 200,
height: 200))
rootView.backgroundColor = .gray
let uiview = UIButton(frame: CGRect(x: 0,
y: 0,
width: 200,
height: 200))
uiview.setTitle("H", for: .normal)
uiview.titleLabel?.font = UIFont.boldSystemFont(ofSize: 200)
uiview.setTitleColor(.black, for: .normal)
uiview.backgroundColor = UIColor.green
uiview.layer.cornerRadius = 100
uiview.layer.masksToBounds = true
rootView.addSubview(uiview)
let center = CGPoint(x: uiview.bounds.width / 2,
y: uiview.bounds.height / 2)
let path = UIBezierPath(arcCenter: center,
radius: 80,
startAngle: 0,
endAngle: .pi,
clockwise: true)
path.append(UIBezierPath(arcCenter: center,
radius: 78,
startAngle: -1,
endAngle: .pi,
clockwise: true))
path.append(UIBezierPath(rect: uiview.bounds))
let maskLayer = CAShapeLayer()
maskLayer.frame = uiview.bounds
maskLayer.path = path.cgPath
maskLayer.backgroundColor = UIColor.clear.cgColor
maskLayer.fillRule = kCAFillRuleEvenOdd
maskLayer.lineWidth = 0
uiview.layer.mask = maskLayer
let rotation = CABasicAnimation(keyPath: "transform.rotation")
rotation.fromValue = 0.0
rotation.toValue = Double.pi * 2
rotation.duration = 10
rotation.repeatCount = 2
maskLayer.add(rotation, forKey: nil)
PlaygroundPage.current.liveView = rootView
我该如何解决这个问题?