实现一个截图分享的功能
- (UIImage *) captureScreen {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [keyWindow.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } 如果要保存到相册: - (void)saveScreenshotToPhotosAlbum:(UIView *)view { UIImageWriteToSavedPhotosAlbum([self captureScreen], nil, nil, nil); }