4

2 つの ViewController 間で遷移しようとしています。私の Transition クラスには、宛先ビュー コントローラーのプロパティがあります。宛先のビューのスクリーンショットを取得しようとするときは、次の方法を使用します。

+ (UIImage *)renderImageFromView:(UIView *)view withRect:(CGRect)frame {
    // Create a new context the size of the frame
    UIGraphicsBeginImageContextWithOptions(frame.size, YES, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    // Render the view 
    [view.layer renderInContext:context];

    // Get the image from the context
    UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();

    // Cleanup the context you created
    UIGraphicsEndImageContext();

    return renderedImage;
}

したがって、画像が必要な場合は、次のようにします。

UIImage *image = [UIImage renderImageFromView:destinationController.view withRect:destinationController.view.bounds];

オレンジ色の背景色とラベルが付いた空の UIViewController で試しました。オレンジ色の背景色は表示されますが、IB で作成されたラベルが表示されません。表示する予定の新しいビューの適切なスクリーンショットを取得する方法はありますか? ありがとう!

4

1 に答える 1