- (void)snapshotScreen:(UIView *)myView {
CGSize size = myView.bounds.size;
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
CGRect rect = myView.frame;
// 自iOS7开始,UIView类提供了一个方法-drawViewHierarchyInRect:afterScreenUpdates: 它允许你截取一个UIView或者其子类中的内容,并且以位图的形式(bitmap)保存到UIImage中
[myView drawViewHierarchyInRect:rect afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//将截屏图片保存在相册中
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
时间: 2024-10-10 05:01:12