在iOS 8之前,我对此没有问题&现在,是的。
日志:
Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y)), function void CGPathMoveToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat), file Paths/CGPath.cc, line 254.这是我的代码:
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();我的目的是将视图转换为图像。
发布于 2014-11-29 01:49:25
检查您正在绘制的内容中是否有空矩形,无论是视图的边界还是图层的内容矩形。我注意到iOS 8上的断言失败,在此之前,空矩形被静默忽略。
我添加了一些...
if (!CGRectIsEmpty(bounds)) {
}我的绘图中的...conditions。
发布于 2015-07-08 08:17:43
我们也遇到了这个问题,并追踪到一个视图,该视图在CALayer上设置了cornerRadius,但大小为零。在我们的例子中,这只发生在设备上-而不是在模拟器上。如果你在回溯中看到_renderBorderInContext和CA_CGContextAddRoundRect,那么你可能看到了同样的事情。
如果设置了拐角半径,则任何尺寸(高度/宽度)中的零大小都将导致此错误。不幸的是,由于这是一个断言,不可能捕获错误并进行恢复,因此我们正在探索在快照之前遍历层次结构的选项,以检测这种情况并通过将cornerRadius设置为0并在调用renderInContext之后恢复。
发布于 2014-12-05 02:10:11
虽然...我会用其他方式解决出口的问题。
致以问候。
- (IBAction)ibaExportar:(id)sender {
NSString *mystr = @"";
NSString *csvstr;
csvstr = [NSString stringWithFormat:@",Cliente,Domicilio,Dueño"];
mystr = [NSString stringWithFormat:@"%@,%@,%@\n",self.numCliente,self.iboDomicilio.text,self.iboDueno.text];
csvstr = [NSString stringWithFormat:@"%@\n%@",csvstr,mystr];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
fileName = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Reporte.csv"]];
NSError *error = NULL;
BOOL written = [csvstr writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!written)
NSLog(@"write failed, error=%@", error);
else{
[self sendEmail];
}
}
- (void) sendEmail {
NSString*subject;
subject= [@"Reporte Cliente " stringByAppendingString:@""];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:subject];
NSData *dataFile = [NSData dataWithContentsOfFile:fileName];
[picker addAttachmentData:dataFile mimeType:@"text/csv" fileName:@"Reporte.csv"];
NSString *emailBody =subject;
[picker setMessageBody:emailBody isHTML:NO];
[self presentViewController:picker animated:YES completion:nil];
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
}https://stackoverflow.com/questions/27193493
复制相似问题