2

I want to use airplay or an HDMI adapter to demonstrate my iOS apps on a big screen.

The problem is that my app only runs in portrait mode and most TVs are in 16:9 aspect ratio and therefore the iPhone screen is very small. To fix this i want to rotate the TV and rotate the output of the iPhone to have a bigger display.

In iOS6 I used CADisplayLink and took a snapshot of the current screen and then drew it on the external screen. Unfortunately the old code didn't work anymore on iOS 7 and was kind of laggy. Is there a good framework for this?

If you don't have any framework suggestions, you could maybe help me make this more efficient?

My code currently looks like this:

- (UIImage *) screenshot {
    UIView* view = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);

    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];


    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (void)drawFrame
{
    UIImageView* contentView = (UIImageView *)[self.secondWindow.rootViewController.view viewWithTag:[@"contentView" hash]];
    CGImageRef screenImg = [self screenshot].CGImage;//UIGetScreenImage();

    contentView.image = [UIImage imageWithCGImage:screenImg scale:1.0 orientation:UIImageOrientationLeft];
}
Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40

1 Answers1

0

I changed my screenshot function like this to get it working fast enough on an iPhone 5s:

- (UIImage *) screenshot {
    UIView* view = [[[[UIApplication sharedApplication] delegate] window] rootViewController].view;
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 2);
    CGContextSetInterpolationQuality(UIGraphicsGetCurrentContext(), kCGInterpolationNone);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

Before I changed the first line I also had some screen flickering on the iPhone's screen. And also changing the InterpolationQuality helped.

If you are running the code on an older iPhone, you could also try setting the ImageContext's scale (the last parameter of the UIGraphicsBeginImageContextWithOptions function) to 1. This will disable the 'retina' resolution on the second screen and make the rendering much faster!

Nils Ziehn
  • 4,118
  • 6
  • 26
  • 40