如何修复在iOS 7中显示为黑色的半透明工具栏截图? [英] How to fix translucent toolbar screenshot showing as black in iOS 7?

查看:109
本文介绍了如何修复在iOS 7中显示为黑色的半透明工具栏截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的顶部当应用程序显示为浅灰色时,底部工具栏显示为黑色。我假设它可能与我在工具栏的.storyboard属性检查器中找到的默认'半透明复选框'有关?

My top and bottom toolbars are showing as black when in the app they show as light gray. I'm assuming it may have something to do with the default 'translucency checkbox' I found in the .storyboard, attributes inspector of the toolbar?

我正在使用UIActivityViewController在电子邮件中拍摄此图像。以下是获取屏幕截图的代码:

I'm using a UIActivityViewController to shoot this image out in an email. Here's the code for grabbing the screenshot:

// Grab a screenshot
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *imageToShare = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


推荐答案

此处的解决方案:iOS:以编程方式制作屏幕截图的最快,最高效的方式是什么?

似乎这应该是Apple框架提供的工厂方法。我把它作为Utils.h / .m类:

Seems like this should be a factory method provided by an Apple framework though. I'm putting this a Utils.h/.m class:

+ (UIImage *)screenshot
{
    CGSize imageSize = CGSizeZero;

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
        imageSize = [UIScreen mainScreen].bounds.size;
    } else {
        imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
    }

    UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        CGContextSaveGState(context);
        CGContextTranslateCTM(context, window.center.x, window.center.y);
        CGContextConcatCTM(context, window.transform);
        CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
        if (orientation == UIInterfaceOrientationLandscapeLeft) {
            CGContextRotateCTM(context, M_PI_2);
            CGContextTranslateCTM(context, 0, -imageSize.width);
        } else if (orientation == UIInterfaceOrientationLandscapeRight) {
            CGContextRotateCTM(context, -M_PI_2);
            CGContextTranslateCTM(context, -imageSize.height, 0);
        } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
            CGContextRotateCTM(context, M_PI);
            CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);
        }
        if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
            [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
        } else {
            [window.layer renderInContext:context];
        }
        CGContextRestoreGState(context);
    }

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

这篇关于如何修复在iOS 7中显示为黑色的半透明工具栏截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆