Clearing content of NSWindow
I have used the (v开发者_如何学Coid)drawRect:(NSRect)dirtyRect to draw triangles, which is displayed in a NSWindow. My triangles are drawn, but the problem is removing them from the window. I have to figure out how to remove/clear the lines that are drawn from the strokeLineFromPoint:toPoint using a simple method.
Thanks in advance!
You have to create a view and set it to the view property of the NSWindow. Then, draw using the view's drawRect method. The NSWindow does not have a drawRect method. Also, If you want to change the drawing, you have to redraw the part or the entire view.
You need to use the setNeedsDisplay method to redraw the view. So, you'd need something like this:
-(void) deleteStuff{
removeTriangles = YES; //Boolean value
[myView setNeedsDisplay];
}
Then, inside the drawRect function, simply put all your drawing code inside an if statement.
(void)drawRect:(NSRect)dirtyRect{
if(!removeTriangles){
//Rest of drawing code
}
}
Don't forget to set removeTriangles to NO originally so you can draw the triangles!
Hope this helps.
精彩评论