Question

i'm trying to draw a line from the originate point of an image view to its destination point. my problem is (i guess) how to set the superview as current drawing context (from the image view). can someone help please. this is the code i'm using in image view..

    //UIGraphicsPopContext();
CGContextRef context = UIGraphicsGetCurrentContext(); //(problem here????????)
CGContextSetLineWidth(context, 5.0); 
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 

CGContextMoveToPoint(context, startLocationInView.x, startLocationInView.y); 
CGContextAddLineToPoint(context, destinationPositionInView.x, destinationPositionInView.y); 
CGContextStrokePath(context);
Was it helpful?

Solution

You cannot draw in other views. What you should do is expand your view's bounds to cover the whole area in which you want to draw.

Alternatively, you could add a new CALayer to your view's layer to cover areas that are outside of your view's bounds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top