Note that there are some explanatory texts on larger screens.

plurals
  1. PORedrawing a path using CGContextStrokePath after initial load
    primarykey
    data
    text
    <p>I have a basic map view in my app which contains a set of user definable way points. When the view is loaded I draw a path connecting the way points. This works well.</p> <p>However, when the user drags a way point around the view, I would like it to re-draw the paths and that is my problem. I dont know how to hacant get it to draw anything after the first time. Here's my code:</p> <pre><code>- (void)drawRect:(CGRect)rect { ////// works perfectly context = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(context, 1, 0, 1, .7); CGContextSetLineWidth(context, 20.0); WaypointViewController *w = [arrayOfWaypoints objectAtIndex:0]; CGPoint startPoint = w.view.center; CGContextMoveToPoint(context, startPoint.x, startPoint.y); for (int i = 1; i&lt;[arrayOfWaypoints count]; i++) { WaypointViewController *w2 = [arrayOfWaypoints objectAtIndex:i]; CGPoint nextPoint = w2.view.center; CGContextAddLineToPoint(context,nextPoint.x, nextPoint.y); } CGContextStrokePath(context); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (moving) { UITouch *touch = [touches anyObject]; currentWaypoint.view.center = [touch locationInView:self]; [delegate setUserInteraction:NO]; [self drawInContext:context]; [NSThread detachNewThreadSelector:@selector(drawInContext:) toTarget:self withObject:nil]; } } - (void)drawInContext:(CGContextRef)context { ///gets called, but does nothing CGContextSetRGBStrokeColor(context, 1, 0, 1, .7); CGContextSetLineWidth(context, 20.0); WaypointViewController *w = [arrayOfWaypoints objectAtIndex:0]; CGPoint startPoint = w.view.center; CGContextMoveToPoint(context, startPoint.x, startPoint.y); for (int i = 1; i&lt;[arrayOfWaypoints count]; i++) { WaypointViewController *w2 = [arrayOfWaypoints objectAtIndex:i]; CGPoint nextPoint = w2.view.center; CGContextAddLineToPoint(context,nextPoint.x, nextPoint.y); } CGContextStrokePath(context); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload