首页 > 解决方案 > CALayerInvalidGeometry CALayer bounds contains NaN: [0 0

问题描述

将 UIview 渲染为图像时应用程序崩溃 将视图渲染为图像的代码

- (UIImage*)imageOfSelf
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);

    [self.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *imageOfSelf = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return imageOfSelf;
}

收到此错误

CALayer bounds contains NaN: [0 0; 1.25987e-321 nan]. Layer: <CALayer:0x2834f8580; position = CGPoint (0 0); bounds = CGRect (0 0; 0 0); delegate = <UIView: 0x10d425820; frame = (0 0; 0 0); layer = <CALayer: 0x2834f8580>>; allowsGroupOpacity = YES; >

类似的问题已经存在,但这并不能解决我的问题

标签: iosobjective-cswift

解决方案


推荐阅读