【问题标题】:sublayer with non-finite position [inf inf]具有非有限位置的子层 [inf inf]
【发布时间】:2015-10-03 04:53:55
【问题描述】:

我正在使用第三个用 Objective-C 编写的 CocoaPods 库来截取 UITextView 的屏幕截图。 iOS 8 没问题,但是在我更改 iOS 9 和 Swift 2 的语法后,它会抛出一个错误:

由于未捕获的异常 'CALayerInvalidGeometry' 导致应用程序终止,原因:'sublayer with non-finite position [inf inf]'

这是库中的代码:

- (UIImage *)screenshotForCroppingRect:(CGRect)croppingRect
{
    UIGraphicsBeginImageContextWithOptions(croppingRect.size, NO, [UIScreen mainScreen].scale);
    // Create a graphics context and translate it the view we want to crop so
    // that even in grabbing (0,0), that origin point now represents the actual
    // cropping origin desired:
    CGContextRef context = UIGraphicsGetCurrentContext();
    if (context == NULL) return nil;

    NSLog(@"hiii :%f" , croppingRect.size.width);

    CGContextTranslateCTM(context, -croppingRect.origin.x, -croppingRect.origin.y);

    [self layoutIfNeeded];
    [self.layer renderInContext:context];

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

问题出在这一行:

[self.layer renderInContext:context];

我意识到这是因为我正在尝试拍摄包含 UIScrollView 的 UIView 的快照。如果我删除 UIScrollView 子视图,错误就消失了。

那么这是什么意思呢?

具有非有限位置的子层 [inf inf]

任何人有同样的问题,你是如何解决的?

【问题讨论】:

    标签: ios swift2 ios9


    【解决方案1】:

    这是我解决这个问题的方法:

    关注这篇文章

    https://github.com/facebook/ios-snapshot-test-case/issues/112

    错误来自我使用的库,因此请搜索所有文件并找出

    CGRectNull
    

    并将它们全部更改为

    CGRectZero
    

    这解决了问题。

    【讨论】:

    • 我简直不敢相信,但它修复了它:D 看起来苹果公司有人使用 == 有点太频繁了 ;)
    猜你喜欢
    • 2021-02-18
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    相关资源
    最近更新 更多