Why this code isn't being executed correctly. I have tried setNeedsDisplay and setNeedsLayout but this code doesn't appear to be executed. Even when it does execute, it executes when its not supposed to and it executes it wrong meaning it draws the line in the wrong place and with random length. - (void)drawNW {
NSLog(@"%f",x1);
NSLog(@"%f",y1);
CGContextSetStrokeColorWithColor(c, [UIColor blueColor].CGColor);
CGContextSetLineWidth(c, 10.0);
CGContextMoveToPoint(c, x1, y1);
CGContextAddLineToPoint(c, -(sqrtf(2)/2)*length + x1, ((sqrtf(2)/2)*length + y1));
CGContextStrokePath(c);
length = line.bounds.size.height;
}
Length, x1, and y1 are floats constantly changing at a interval of 0.1 seconds by a NSTimer:
NWTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(startMoving) userInfo:nil repeats:YES];
the timer calls this code which calls drawNW:
x1 = x1-2.5;
y1 = y1-2.5;
length= length+5;
[self drawNW];