【问题标题】:Take UIImage of UIViews layer property取 UIViews 图层属性的 UIImage
【发布时间】:2016-12-12 12:32:42
【问题描述】:

我通过调用[self.layer addSublayer:shapeLayer]; 将多个CAShapeLayers 添加到我的UIView 子类的layer 属性中

为了在UIImage 中捕获这些层,我实现了以下方法,该方法旨在获取layer 属性的图像。

- (UIImage *)takeImage {

    UIGraphicsBeginImageContext(self.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    if (context) {

        [self.layer renderInContext:context];

        UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return snapshotImage;
    }

    return nil;
}

我的问题是,生成的图像完全是空白的。为什么会这样?

【问题讨论】:

  • 你有什么问题?

标签: uiimage core-graphics core-animation calayer cashapelayer


【解决方案1】:

图片很棒!没有正确设置 IBOulet。

【讨论】:

    猜你喜欢
    • 2011-06-27
    • 1970-01-01
    • 2012-05-26
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多