GCD开启子线程下载图片
//开启子线程下载图片
//1.获取一个全局串行队列
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
__weak typeof(self) weakSelf = self;
//2.把任务添加到队列中执行
dispatch_async(queue, ^{
NSURL *url = [NSURL URLWithString:_imgString];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage * bgImage = [UIImage imageWithData:imageData];
bgImage = [bgImage applyLightEffectAtFrame:CGRectMake(0, 0, bgImage.size.width, bgImage.size.height)];
//3.回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.backImageView.image = bgImage;
});
});