具有非有限位置的子层[inf inf] [英] sublayer with non-finite position [inf inf]
问题描述
我正在使用Objective-C编写的第三个CocoaPods库来截取UITextView的截图。对于iOS 8来说没关系,但是在我更改iOS 9和Swift 2的语法后,它会抛出一个错误:
I am using a third CocoaPods library written in Objective-C to take a screenshot of a UITextView. It was OK for iOS 8, but after I change the syntax for iOS 9 and Swift 2, it throws an error:
终止app到期未被捕获的异常'CALayerInvalidGeometry',原因:'子层有非有限位置[inf inf]'
Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'sublayer with non-finite position [inf inf]'
这是来自的代码library:
Here is the code from the library:
- (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子视图,则错误消失。
I realize this is because I am trying to take a snapshot of the UIView which contain a UIScrollView. If I remove the UIScrollView subview, the error is gone.
那是什么意思?
具有非有限位置的子层[ inf inf]
sublayer with non-finite position [inf inf]
任何人都有同样的问题,你是如何解决的?
Anyone having the same issue and how did you solve it?
推荐答案
以下是我如何解决这个问题:
Here is how I solved this:
关注此帖子
https://github.com/facebook/ios-snapshot-test-case/issues / 112
错误来自我使用的库,因此搜索所有文件并查找
the error is coming from the library I used, so do a search on all the files and find out
CGRectNull
并将它们全部更改至
CGRectZero
解决了这个问题。
这篇关于具有非有限位置的子层[inf inf]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!