Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用CGContextDrawImage的块中的图像位置错误_Ios_Core Text_Cgcontextdrawimage - Fatal编程技术网

Ios 使用CGContextDrawImage的块中的图像位置错误

Ios 使用CGContextDrawImage的块中的图像位置错误,ios,core-text,cgcontextdrawimage,Ios,Core Text,Cgcontextdrawimage,接着我使用核心文本绘制文本,我想将web图像添加到视图中。 当我使用下面的代码时,除了等待下载时间外,一切都正常 但是这段代码阻塞了主线程,当我这样替换代码时: 它变成有线,图像的位置是错误的。 - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetTextMatrix(context, CGAffineTransformIdentity

接着我使用核心文本绘制文本,我想将web图像添加到视图中。 当我使用下面的代码时,除了等待下载时间外,一切都正常

但是这段代码阻塞了主线程,当我这样替换代码时:

它变成有线,图像的位置是错误的。

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CTFrameDraw((CTFrameRef)self.coreTextFrame, context);

    for (NSArray *imageData in self.images) {
        UIImage *image = [UIImage imageWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:0]]]];
        CGRect imageBounds = CGRectFromString([imageData objectAtIndex:1]);
        CGContextDrawImage(context, imageBounds, image.CGImage);
    }
}
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CTFrameDraw((CTFrameRef)self.coreTextFrame, context);

    for (NSArray *imageData in self.images) {

        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:  [imageData objectAtIndex:0]]];
        __block UIImage *image = nil;
        CGRect imageBounds = CGRectFromString([imageData objectAtIndex:1]);

        AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request success:^(UIImage *downloadImage){
            image = downloadImage;
            CGContextDrawImage(context, imageBounds, image.CGImage);
        }];

        [operation start];

    }
}