我正在使用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]
任何人都有同样的问题,你是如何解决的?