dyfviewcontroller.m//623-08-Queue group////Created by Dyf on 14-6-23.//Copyright (c) 2014 ___fullusername___. All rights reserved.//#import "DYFViewController.h" @interface Dyfviewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview *iconv1; @property (weak, nonatomic) Iboutlet Uiimageview *iconv2; @property (weak, nonatomic) Iboutlet Uiimageview *bigiconv; @end @implementation dyfviewcontroller-(void) viewdidload{[Super viewdidload];//do any addition Al Setup after loading the view, typically from a nib.} -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{NSLog (@ "%@", [Nsthread CurrentThread]); dispatch_group_t group = Dispatch_group_create (); dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default, 0); __block UIImage *icon1 = nil; Dispatch_group_async (group, queue, ^{NSLog (@ "%@", [NSTHread CurrentThread]); Icon1 = [Self imagewithurl:@ "http://image.cache.xiu8.com/live/125/125/997729.jpg"]; }); __block UIImage *icon2 = nil; Dispatch_group_async (group, queue, ^{NSLog (@ "%@", [Nsthread CurrentThread]); Icon2 = [Self imagewithurl:@] Http://news.baidu.com/z/resource/r/image/2014-06-22/b2a9cfc88b7a56cfa59b8d09208fa1 Fb.jpg "]; }); Dispatch_group_notify (Group, Dispatch_get_main_queue (), ^{NSLog (@ "%@", [Nsthread CurrentThread]); Self.iconV1.image = Icon1; Self.iconV2.image = Icon2; Uigraphicsbeginimagecontextwithoptions (Cgsizemake (max.), NO, 0); [Icon1 drawinrect:cgrectmake (0, 0, 100, 100)]; [Icon2 drawinrect:cgrectmake (100, 0, 100, 100)]; Self.bigIconV.image = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); });} -(UIImage *) Imagewithurl: (NSString *) iconpath{NSLog (@ "%@", [Nsthread CurrentthreAD]); Nsurl *url = [Nsurl Urlwithstring:iconpath]; NSData *data = [NSData Datawithcontentsofurl:url]; return [UIImage Imagewithdata:data];} @end
Summary:
------------Queue Group------
1. There is a need
• First: Perform 2 time-consuming operations asynchronously, respectively
• Second: Wait 2 after each asynchronous operation is completed, then go back to the main thread to perform the operation
2. If you want to achieve these requirements quickly and efficiently, consider using queue groups