を持っているのでUITableView
、その表示部分をキャプチャして、に入れたいと思いUIImage
ます。これを行う方法はありますか?
編集
以下の自己回答
を持っているのでUITableView
、その表示部分をキャプチャして、に入れたいと思いUIImage
ます。これを行う方法はありますか?
編集
以下の自己回答
返信ありがとうございます。すべての回答はUIViewで機能しますが、UITableViewでは機能しません。少なくともテーブルがスクロールしたときは機能しません。スクロールすると、キャプチャされた画像は黒または透明に表示されます。私は以前に以下のものと同様の解決策を試しました。人々は答えが明白であると思っていたと思います、そしてそれが私が反対票を投じた理由です-そのような明白な質問をするのに十分いたずらだったからです。
とにかく、本当の解決策は、テーブルのcontentOffsetを使用する必要があるということです。
- (UIImage *) imageWithTableView:(UITableView *)tableView
{
UIView *renderedView = tableView;
CGPoint tableContentOffset = tableView.contentOffset;
UIGraphicsBeginImageContextWithOptions(renderedView.bounds.size, renderedView.opaque, 0.0);
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(contextRef, 0, -tableContentOffset.y);
[tableView.layer renderInContext:contextRef];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
UIGraphicsBeginImageContext(someView.bounds.size);
[someView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
この質問から引用。
- (UIImage *)captureView {
//hide controls if needed
CGRect rect = [yourTableView bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[yourTableview.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
UIGraphicsBeginImageContext(tableView.bounds.size);
[tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
たぶん、それらの投稿は、UIViewをその子と一緒にレンダリングするのに役立つでしょう