我正在使用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
这解决了这个问题.