Reposition CGPath/UIBezierPath in View

后端 未结 4 865
梦如初夏
梦如初夏 2021-02-03 10:32

Is it possible to reposition an already drawn CGPath/UIBezierPath on a view? I would like to move or change a path\'s position then perhaps recall the drawinRect method to just

4条回答
  •  既然无缘
    2021-02-03 10:48

    /// Provide cgpath to it and tanslate it by given point.

    func translate(path : CGPath?, by point: CGPoint) -> CGPath? {
    
        let bezeirPath = UIBezierPath()
        guard let prevPath = path else {
            return nil
        }
        bezeirPath.cgPath = prevPath
        bezeirPath.apply(CGAffineTransform(translationX: point.x, y: point.y))
    
        return bezeirPath.cgPath
    }
    

提交回复
热议问题