直接調(diào)用截屏的方法即可蒸播,
//截屏的方法
- (void)screenCapture{
UIImage *image = [self captureScrollView:self.collectionView];
//保存到相冊
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
NSLog(@"截屏結(jié)束啦!");
}
//傳入需要截屏的scrollView / tableView / collectionView
- (UIImage *)captureScrollView:(UIScrollView *)scrollView {
//設(shè)置控件顯示的區(qū)域大小
scrollView.frame = CGRectMake(0, _collectionView.frame.origin.y, _collectionView.contentSize.width, _collectionView.contentSize.height);
//設(shè)置截屏大小(截屏區(qū)域的大小必須要跟視圖控件的大小一樣)
UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0.0);
[[scrollView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}