Swift 不接受接触的用户

Swift 不接受接触的用户,swift,uiview,calayer,cashapelayer,cgpath,Swift,Uiview,Calayer,Cashapelayer,Cgpath,我在UIView中制作了一个CAShapeLayer,如下所示: let shapeMask: CAShapeLayer = { let sl = CAShapeLayer() sl.bounds = CGRect(x: 0, y: 0, width: 133, height: 133) sl.lineWidth = 2 sl.strokeColor = UIColor.green.cgColor sl.fi

我在UIView中制作了一个CAShapeLayer,如下所示:

    let shapeMask: CAShapeLayer = {
        let sl = CAShapeLayer()
        sl.bounds = CGRect(x: 0, y: 0, width: 133, height: 133)
        sl.lineWidth = 2
        sl.strokeColor = UIColor.green.cgColor
        sl.fillColor = UIColor.purple.cgColor
        let shapeLayerPath = UIBezierPath()
        shapeLayerPath.addArc(withCenter: CGPoint(x: 0, y: 0), radius: 68, startAngle: -.pi/2, endAngle: -.pi/4, clockwise: true)
        shapeLayerPath.addArc(withCenter: CGPoint(x: 0, y: 0), radius: 180, startAngle: -.pi/4, endAngle: -.pi/2, clockwise: false)
        shapeLayerPath.move(to: CGPoint(x: 0, y: -68))
        shapeLayerPath.addLine(to: CGPoint(x: 0, y: -180))
        shapeLayerPath.close()
        sl.path = shapeLayerPath.cgPath            
        return sl
    }()
我将其添加到UIView的init中的视图中,如下所示:

    layer.addSublayer(shapeMask)
    shapeMask.frame = CGRect(x: 181, y: 180, width: 133, height: 133)
看起来是这样的:

我正在使用
touchesbreated
查看用户是否触摸ShapeLayer的内部

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {        
    let touchOne = touches.first
    let point = touchOne!.location(in: self)

    if (shapeMaskOne.path?.contains(point))! {
        print("shapeMaskTouched")
    }
}
override func touchsbegind(touch:Set,with event:UIEvent?{
让touchOne=touch.first
让点=touchOne!。位置(in:self)
如果(shapeMaskOne.path?.contains(point)){
打印(“形状标记”)
}
}

但当我触摸到ShapeLayer内部时,什么也没有打印出来。我做错了什么?

@Leo我的错。它现在更新了。不要更改形状边界,从常规形状开始shape@Leo更改形状边界没有任何作用,它只是移动了形状