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

我正在使用Objective-C编写的第三个 CocoaPods库来截取UITextView的截图.对于iOS 8来说没关系,但是在我更改了iOS 9和 Swift 2的语法后,它会抛出一个错误

Terminating app due to uncaught exception ‘CALayerInvalidGeometry’,reason: ‘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子视图,则错误消失.

那么这是什么意思?

sublayer with non-finite position [inf inf]

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

解决方法

以下是我解决这个问题的方法

关注这篇文章

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

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

CGRectNull

并将它们全部改为

CGRectZero

解决了这个问题.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...