Non-end sublayer [inf inf]

I am using the third CocoaPods library written in Objective-C to take a screenshot of a UITextView. This was fine for iOS 8, but after I changed the syntax for iOS 9 and Swift 2, it throws an error:

Application termination due to uncaught exception "CALayerInvalidGeometry", reason: "sublevel with non-final position [inf inf]"

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; } 

The problem is this line:

 [self.layer renderInContext:context]; 

I understand this because I am trying to take a snapshot of a UIView that contains a UIScrollView. If I remove the UIScrollView routine, the error will disappear.

And what does it mean?

sublevel with non-final position [inf inf]

Does anyone have the same problem and how did you solve it?

+6
source share
1 answer

Here is how I solved it:

After this message

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

the error comes from the library that I used, so search all the files and find out

 CGRectNull 

and change them all to

 CGRectZero 

This solved the problem.

+8
source

All Articles