iOS 8崩溃 - renderInContext:UIGraphicsGetCurrentContext()

A. *_*ejo 5 core-graphics objective-c ios ios8

在iOS 8之前,我现在没有问题,是的.

日志:

Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y)), function void CGPathMoveToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat), file Paths/CGPath.cc, line 254.
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

UIImage* image = nil;

CGSize imageSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);

UIGraphicsBeginImageContextWithOptions(imageSize, NO , 0.0f);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; // <- ERROR

image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

我的目的是将视图转换为图像.

Phi*_*lls 2

检查您正在绘制的内容中是否有空矩形,无论是视图的边界还是图层的内容矩形。我注意到 iOS 8 上的断言失败,之前空矩形被默默地忽略了。

我添加了一些...

if (!CGRectIsEmpty(bounds)) {
}
Run Code Online (Sandbox Code Playgroud)

...我的绘图中的条件。