Advertisement
Guest User

Untitled

a guest
May 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.06 KB | None | 0 0
  1. enum PathType {
  2.         case yolo, vision
  3.     }
  4.    
  5.     private let yoloPath = UIBezierPath()
  6.     private let visionPath = UIBezierPath()
  7.     private let yoloLayer = CAShapeLayer()
  8.     private let visionLayer = CAShapeLayer()
  9.     private var previousTouchPoint = CGPoint.zero
  10. func drawPath(at point: CGPoint, pathType: PathType) {
  11.         let path: UIBezierPath
  12.         let shapeLayer: CAShapeLayer
  13.         switch pathType {
  14.         case .yolo:
  15.             path = yoloPath
  16.             shapeLayer = yoloLayer
  17.         case .vision:
  18.             path = visionPath
  19.             shapeLayer = visionLayer
  20.         }
  21.        
  22.         path.move(to: point)
  23.         if self.previousTouchPoint !=  CGPoint.zero {
  24.             path.addLine(to: self.previousTouchPoint)
  25.         }
  26.        
  27.         self.previousTouchPoint = point
  28.         shapeLayer.path = path.cgPath
  29.         switch pathType {
  30.         case .yolo:
  31.              shapeLayer.strokeColor = UIColor.red.cgColor
  32.         case .vision:
  33.              shapeLayer.strokeColor = UIColor.green.cgColor
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement