How can I render an in-memory UIViewController's view Landscape?
        Posted  
        
            by Aaron
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Aaron
        
        
        
        Published on 2010-04-10T22:28:26Z
        Indexed on 
            2010/04/10
            22:33 UTC
        
        
        Read the original article
        Hit count: 318
        
I'm trying to render an in-memory (but not in hierarchy, yet) UIViewController's view into an in-memory image buffer so I can do some interesting transition animations. However, when I render the UIViewController's view into that buffer, it is always rendering as though the controller is in Portrait orientation, no matter the orientation of the rest of the app. How do I clue this controller in?
My code in RootViewController looks like this:
MyUIViewController* controller = [[MyUIViewController alloc] init];
int width = self.view.frame.size.width;
int height = self.view.frame.size.height;
int bitmapBytesPerRow = width * 4;
unsigned char *offscreenData = calloc(bitmapBytesPerRow * height, sizeof(unsigned char)); 
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef offscreenContext = CGBitmapContextCreate(offscreenData, width, height, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); 
CGContextTranslateCTM(offscreenContext, 0.0f, height);
CGContextScaleCTM(offscreenContext, 1.0f, -1.0f);
[(CALayer*)[controller.view layer] renderInContext:offscreenContext];
At that point, the offscreen memory buffers contents are portrait-oriented, even when the window is in landscape orientation.
Ideas?
© Stack Overflow or respective owner