大家好!我有一个浅蓝色的点,在代码中它是 userPositionView。
它看起来像这样:
但是在使用图层时,我为这个浅蓝色点(userPositionView)“绘制”了一个半径(他们说半径5米内有一个用户),然后我将图层设置为半透明的深蓝色,重新绘制了我的光蓝点 (userPositionView)。
这是代码:
func setupUserPosition() {
userPositionView = UIView(frame: CGRect(origin: CGPoint(x: 200 , y: 300), size: CGSize(width: 22, height: 22)))
userPositionView.backgroundColor = UIColor(red: 75/255, green: 173/255, blue: 212/255, alpha: 1.0)
userPositionView.layer.cornerRadius = userPositionView.frame.height / 2
userPositionView.layer.borderWidth = 2.5
userPositionView.layer.borderColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1.0).cgColor
userPositionView.setupShadow()
let layer = CAShapeLayer()
layer.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 44, height: 44), cornerRadius: 50).cgPath
layer.fillColor = UIColor(red: 21/255, green: 45/255, blue: 71/255, alpha: 0.3).cgColor
layer.frame.origin = CGPoint(x: (userPositionView.bounds.width / 2) - (44 / 2), y: (userPositionView.bounds.height / 2) - (44 / 2) )
cRadius = layer
}
告诉我,我应该怎么做才能使我的半径不会将浅蓝色点重新着色为深色?
你可以这样做——首先绘制一个带有大圆圈的单独图层,然后在其上覆盖一个带有小圆圈的图层,我将其作为单独的视图进行,大圆圈等于它的大小,小圆圈是缩进 1/4