2

我想使用 airplay 或 HDMI 适配器在大屏幕上演示我的 iOS 应用程序。

问题是我的应用程序仅在纵向模式下运行,并且大多数电视的纵横比为 16:9,因此 iPhone 屏幕非常小。为了解决这个问题,我想旋转电视并旋转 iPhone 的输出以获得更大的显示。

在 iOS6 中,我使用 CADisplayLink 并拍摄当前屏幕的快照,然后将其绘制在外部屏幕上。不幸的是,旧代码在 iOS 7 上不再适用,而且有点滞后。有没有一个好的框架?

如果您没有任何框架建议,您也许可以帮助我提高效率?

我的代码目前如下所示:

- (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];
}
4

1 回答 1

0

我改变了我的截图功能,让它在 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;
}

在我更改第一行之前,iPhone 的屏幕上也有一些屏幕闪烁。并且改变 InterpolationQuality 也有帮助。

如果您在旧 iPhone 上运行代码,您还可以尝试将 ImageContext 的比例(UIGraphicsBeginImageContextWithOptions函数的最后一个参数)设置为1. 这将禁用第二个屏幕上的“视网膜”分辨率,并使渲染速度更快!

于 2014-02-08T11:51:06.917 回答