Etch A Sketch

Source code in Etch.zip

  1. main.m
  2. Class EtchAppDelegate
  3. Class View

We saw a CGMutablePathRef when we filled and stroked the triangle in Japan. The View object contains contains a CGMutablePathRef named path, containing straight lines connecting points. The touchesBegan:withEvent: and touchesMoved:withEvents: methods of the view make the path longer.

Things to try

  1. Erase the drawing when the app is hidden (e.g., when the Home button is pressed) and uncovered. Add the following method to class View. Declare it in View.h (after the }) because it will be called from outside of class View.
    - (void) clearPath;
    
    Define it in View.m:
    - (void) clearPath {
    	CGPathRelease(path);
    	path = CGPathCreateMutable();
    	[self setNeedsDisplay];
    }
    
    Call it in the applicationDidEnterBackground: method of the application delegate.
    	[view clearPath];
    

  2. When we learn about buttons, come back to this app and make an erase button.