Rendering a view to a UIImage in Catalyst

I'm wondering if anyone has seen this, or has a good workaround. Here is a sample of the code I've been using to render a view to a UIImage, in this case, the view is not on screen so I use the layer.render method

     let vc = UIStoryboard(name: storyboardName, bundle: nil).instantiateViewController(withIdentifier: identifier) 

     vc = CGRect.init(origin: CGPoint.zero, size: forSize)

     let renderer = UIGraphicsImageRenderer(size: forSize)
     retVal = renderer.image { (context) in
         vc.view.layer.render(in: context.cgContext)
     }


On iPad and iPhone, the view gets appropriately resized to forSize, but in catalyst, it doesn't. In fact, on the vc, viewWillLayoutSubviews is not called in the catalyst case, whereas it is called by CALayer layoutIfNeeded in iPad/iPhone.


Thoughts?

sorry, that paste was wrong, line 3 should be:


     vc.view.frame = CGRect.init(origin: CGPoint.zero, size: forSize)


but I did discover that adding:


        vc.view.setNeedsLayout()
        vc.view.layoutIfNeeded()

seems to solve it.

Rendering a view to a UIImage in Catalyst
 
 
Q