I am trying to call drawRect in the DrawLines class from UIViewcontroller (would like to set the tappoint variable too from the UIViewController). I would like the lines that are drawn by the DrawLines class to redraw as the user pans. I have come up with the following that produces errors :
UIViewController
@IBAction func pan(sender: UIPanGestureRecognizer) {
DrawLines.tappoint = sender.locationInView(GraphView?()) // trying to set the point
DrawLines.setNeedsDisplay() //trying to redraw display
}
DrawLines
import UIKit
class DrawLines: UIView{
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
var tappoint: CGPoint!
var touched = false
override func drawRect(rect: CGRect) {
if(touched){
var xAxispoint: CGPoint = CGPoint(x: tappoint.x,y: 613)
var vertical = UIBezierPath()
vertical.moveToPoint(tappoint)
vertical.addLineToPoint(xAxispoint)
UIColor.blackColor().setStroke()
vertical.stroke()
var yAxispoint: CGPoint = CGPoint(x: 8, y: tappoint.y)
var horizontal = UIBezierPath()
horizontal.moveToPoint(tappoint)
horizontal.addLineToPoint(yAxispoint)
UIColor.blackColor().setStroke()
horizontal.stroke()
}
}
}