class theView: UIView
{
var kl = 1
var px : CGFloat = 0.0
var py : CGFloat = 0.0
override func drawRect(rect: CGRect)
{
color()
setNeedsDisplay()
}
func move(gesture : UIPanGestureRecognizer)
{
let state = gesture.state
switch state
{
case .Began: print("started")
case .Ended: fallthrough
case .Changed:
let translation = gesture.translationInView(self)
px = translation.x
py = translation.y
print("x:\(px), y:\(py)")
default: break
}
}
func color()
{
let path = UIBezierPath()
path.moveToPoint(CGPointZero)
path.addLineToPoint(CGPoint(x: px, y: py))
UIColor.blueColor().set()
path.stroke()
self.setNeedsDisplay()
}
}
This is the code i have in my view. What am i missing and it doesn't show up on my screen?it does recognise my movement since px
and py
change values.This is part of bigger project so tell me if there are any compilling errors..
my viewController is :
class ViewController: UIViewController, Moveable
{
var k = 1
@IBOutlet weak var sdasd: theView!
{
didSet
{
sdasd.k = self
sdasd.addGestureRecognizer(recognizer)
let panRecognizer = UIPanGestureRecognizer(target: sdasd, action: "move:")
sdasd.addGestureRecognizer(panRecognizer)
sdasd.setNeedsDisplay()
}
}
Also can someone tell me where exactly do i need to put that setNeedsDisplay()
?? do i need to have it in my view controller? my override drawract? thanks. Tell me if you need anything. I want it to draw the line in my view. like painting does