-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Description
方法一:
- (UIImage *)takeSnapshotWithFrame:(CGRect)frame
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0);
[img drawInRect:CGRectMake(0, -frame.origin.y, img.size.width, img.size.height)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
方法二:
- (UIImage *)takeSnapshotWithFrame:(CGRect)frame
{
UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
[self drawViewHierarchyInRect:CGRectMake(0, -frame.origin.y, self.bounds.size.width, self.bounds.size.height) afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
方法二是贴出来讨论的,在效果上面欠缺。 @bref-Chan
Metadata
Metadata
Assignees
Labels
No labels