IOS GCD图片数据异步下载,下载完成后合成显示

  关于GCD使用详解,请看我的上一篇blog:http://www.cnblogs.com/xin-lang/p/6278606.html

  前段时间遇到个需要异步下载,下载完成后再组合显示的东西。这里我采用了    dispatch_group_create()来实现。废话不多说,一言不合就上代码:

 

//创建GCD队列

dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t defaultQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

//执行异步加载
    dispatch_group_async(group, defaultQueue, ^{
        NSLog(@"异步下载1");
    });
    dispatch_group_async(group, defaultQueue, ^{
        NSLog(@"异步下载2");
    });
    dispatch_group_async(group, defaultQueue, ^{
        NSLog(@"异步下载3");
    });
    dispatch_group_async(group, defaultQueue, ^{
        NSLog(@"异步下载4");
    });
    dispatch_group_async(group, defaultQueue, ^{
        NSLog(@"异步下载5");
    });
   //组合图片
    dispatch_group_notify(group, defaultQueue, ^{
        NSLog(@"下载结束,开始组合,显示要回到主线程");
    });

 

posted @ 2017-01-12 15:48  小固编程  阅读(1099)  评论(0编辑  收藏  举报