One, multi-threaded
1. Home column: Handles multi-touch and all UI actions (cannot block, main sync update UI)
dispatch_queue_t mainqueue = dispatchg_get_main_queue (); Get the main thread
Dispatch_async (Queue, ^{}); Execute block asynchronously
dispatch_queue_t queue = dispatch_queue_create("name", NULL);//Create a
2, the update UI must be executed in the main thread, there are two methods
1 //The update UI must be executed in the main thread, in two ways,2 //one is to specify that the delegate is in the main thread3Nsurlsession *session =[nsurlsession sessionwithconfiguration:configuration 4 Delegate: Nil5 Delegatequeue:[nsoperationqueue Mainqueue]];6Nsurlsessiondownloadtask *task;7Task =[Session downloadtaskwithrequest:request 8completionhandler:^ (Nsurl *localfile,nsurlresponse *response,nserror *error) {9 //Here you can invoke the UI operation directly.Ten }]; One [Task resume]; A - //one is to not specify a delegate: - //then if the main thread is called in Completionhandler, it is equivalent to Completionhandler calling the main thread in a queue that is not the main thread. theNsurlsession *session =[Nsurlsession sessionwithconfiguration:configuration]; -Nsurlsessiondownloadtask *task; -Task =[Session Downloadtaskwithrequest:request -completionhandler:^ (Nsurl *localfile,nsurlresponse *response,nserror,error) { + //because the main thread delegate is not called, the main thread asynchronous queue is called: Two ways to invoke UI actions -Dispatch_async (Dispatch_get_main_queue (), ^{//The UI action can be invoked here}) ; + //or: A [Self performselectoronmainthread: @selector (douithingsfunction) Withobject: Nil Waitutildone:no]; at }]; - //Restart (default is pending) -[Task resume];
Second, Uiscrollview
1.
Contentsize represents the range of scrolling
scrollview.contentsize = Cgsizemake (a);
Current range shown (upper-left corner coordinates)
Cgpoint *visiblep= Scrollview.contenetoffset;
2. Zoom
1. Set the zoom ratio
ScrollView. Minimumzoomscale = 0.5;
ScrollView. Maximumzoomscale = 2.0;
2. Scaling delegates
-(UIView *) viewforzoominginscrollview:(Uiscrollview *) sender;//returns which view can be scaled
3, or to achieve gesture scaling
@property (nonatomic) float Zoomscale;
-(void)Setzoomingscale:(float) scale animated: (BOOL) animated;
-(void)zoomtorect:(CGRect) zoomrect animated: (BOOL) animated;
Third, run the demo
This demo is to download the pictures on the web, using multi-threading method [There are main thread also has another thread], while the picture is displayed in our Uiscrollview, set the scaling column, but also in the download process to set the loaded image
1, the operation effect is as follows:
2, attention to some problems
(1 Our uiimage does not use synthesize but does not have an error because we do not have a synthetic instance variable, but we use the imageview.image to define it, without using _image
(2
The first: nsurlsessionconfiguration there are three types of Session mode, default, ephemeral temporary, background running in the background
Second: multi-threaded tasks, the long process of network requests may have subsequent changes, the URL address may be subject to change, if the change, we will discard the obtained content.
The third: The above execution is present in the non-primary queue, but the following is to do is to refer to the image information needs to update the UI operation, preferably in the main queue to execute
Demo;http://pan.baidu.com/s/1qwywliw
OC Development _storyboard--Multi-threading, Uiscrollview