How do I detect a touch on a UIBezierPath and move a ball along that?

前端 未结 5 2098
孤城傲影
孤城傲影 2020-12-05 12:20

How do I move a ball along a specific UiBezierPath? Is that possible?

I\'ve tried everything including doing a hit test using

-(BOOL)containsPoint:(         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 12:43

    Swit: for @rakesh's answer

     func tapTargetForPath(_ path: CGPath) -> UIBezierPath? {
        let path = UIBezierPath(cgPath: path)
       guard let tapTargetPath = CGPath(__byStroking: path.cgPath,
               transform: nil,
               lineWidth: CGFloat(fmaxf(35.0, Float(path.lineWidth))),
               lineCap: path.lineCapStyle,
               lineJoin: path.lineJoinStyle,
               miterLimit: path.miterLimit) else {
                return nil
        }
    
        return UIBezierPath(cgPath: tapTargetPath)
    }
    

提交回复
热议问题