1. Monitor the shake Action 1> make the current view controller the first responder // you must first make the current view controller the first responder to respond to the action time [self becomeFirstResponder]; 2> implement response method-inherit from UIResponder method copy code 1-(void) motionBegan :( UIEventSubtype) motion withEvent :( UIEvent *) event2 {3 // if the action type is shake [shake] 4 if (motion = UIEventSubtypeMotionShake) {5 6 // call screenshot Method 7 [self snapshot]; 8} 9} copy code 2. screenshot Note: 1> when obtaining an image, you must enable the image context first, obtain the context 2> the method to be executed after being saved must be in a fixed format, that is, copy the code in the format shown in the following code 1 # pragma mark-click screenshot 2-(IBAction) snapshot 3 {4 // 1. enable image context [You must enable the context before proceeding to step 2. The sequence cannot be changed] 5 UIGraphicsBeginImageContext (self. view. bounds. size); 6 7 // 2. get context 8 CGContextRef context = UIGraphicsGetCurrentContext (); 9 10 // 3. render the current view layer to the current context 11 [self. view. layer renderInContext: context]; 12 13 // 4. obtain the image 14 UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); 15 16 // 5. disable image Context 17 UIGraphicsEndImageContext (); 18 19 // 6. save the image to the album 20 UIImageWriteToSavedPhotosAlbum (image, self, @ selector (image: didFinishSavingWithError: contextInfo :), nil ); 21} 22 23 # method called after the pragma mark is saved [fixed format] 24-(void) image :( UIImage *) image didFinishSavingWithError :( NSError *) error contextInfo :( void *) contextInfo25 {26 if (error) {27 NSLog (@ "error-% @", error. localizedDescription); 28} else {29 NSLog (@ "saved successfully"); 30} 31} copy the code