我有一个UIScrollView,其中包含需要通过电子邮件发送的内容。屏幕截图仅捕获屏幕上的可见区域。滚动视图大小为768 x 2000.我目前使用的方法如下:
- (IBAction) Email
{
UIImage* image = nil;
UIGraphicsBeginImageContext(_scrollView.contentSize);
{
CGPoint savedContentOffset = _scrollView.contentOffset;
CGRect savedFrame = _scrollView.frame;
_scrollView.contentOffset = CGPointZero;
_scrollView.frame = CGRectMake(0, 0, _scrollView.contentSize.width, _scrollView.contentSize.height);
[_scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
_scrollView.contentOffset = savedContentOffset;
_scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 0.95);
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"Attachment.jpeg"];
[self presentModalViewController:mc animated:YES];
}
}
感谢您的回复。我意识到我只有滚动视图作为插座而不是属性。将代码更改为以下内容并修复了问题;