Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reposition CGPath/UIBezierPath in View

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 show the drawing again.

like image 811
SleepNot Avatar asked Jun 18 '13 12:06

SleepNot


1 Answers

/// Translate cgPath from its center to give point.No need to move shape layer .Moving path will make app smooth

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
}
like image 150
Arnav Avatar answered Oct 01 '22 01:10

Arnav