非有限位置的子层
我正在使用Objective-C中编写的第三个CocoaPods库来截取UITextView。 对于iOS 8来说是可以的,但是当我更改iOS 9和Swift 2的语法之后,它会抛出一个错误:
终止应用程序由于未捕获的exception“CALayerInvalidGeometry”,原因:“非有限位置的子层[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]
任何人都有同样的问题,你是如何解决的?
这是我解决这个问题的方法:
在这篇文章之后
https://github.com/facebook/ios-snapshot-test-case/issues/112
错误是来自我使用的库,所以做一个search所有的文件,并找出
CGRectNull
并将其全部更改为
CGRectZero
这解决了这个问题。