• 触发截屏事件:

    NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
    [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
                                                object:nil
                                                 queue:mainQueue
                                            usingBlock:^(NSNotification *note) {
                                                // executes after screenshot
    
                                                NSLog(@"akixie");
    
                                            }];
    
  • 截图方法:

    - (UIImage *)imageWithScreenshot{
    
      UIGraphicsBeginImageContextWithOptions(self.view.window.bounds.size, NO, 0);
    
      [self.view.window drawViewHierarchyInRect:self.view.window.bounds afterScreenUpdates:YES];
    
      UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
    
      return snapshotImage;
    }