1. Scroll the view using the party method:
1 @interfaceImageviewcontroller ()<UIScrollViewDelegate>//declaring a delegate2@property (Strong, nonatomic) Uiimageview *ImageView;3@property (Strong, nonatomic) UIImage *image;4@property (Weak, nonatomic) Iboutlet Uiscrollview *ScrollView;5@property (Weak, nonatomic) Iboutlet Uiactivityindicatorview *spinner;6 @end7 8-(void) Setscrollview: (Uiscrollview *) ScrollView9 {Ten_scrollview =ScrollView; One _scrollview.minimumzoomscale = 0.2; //Setting the Zoom attribute A _scrollview.maximumzoomscale = 2.0; //Setting the Zoom attribute - _scrollview.delegate = self; //Set Delegate - self.scrollView.contentSize = self.image? Self.image.size:CGSizeZero; //to set the scrolling view movable properties the } - - //Implementing a scale delegate --(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView + { - returnSelf.imageview; + } A at-(Uiimageview *) ImageView - { - if(!_imageview) { -_imageview =[[Uiimageview alloc] init]; - } - return_imageview; in } - to-(UIImage *) Image + { - returnSelf.imageView.image; the } * $-(void) SetImage: (UIImage *) ImagePanax Notoginseng { -Self.imageView.image =image; the [Self.imageview SizeToFit]; + self.scrollView.contentSize = self.image? Self.image.size:CGSizeZero; //to set the scrolling view movable properties A } the +-(void) Viewdidload - { $ [Super Viewdidload]; $ [Self.scrollview AddSubview:self.imageView]; -}
2. Multithreading Call method
1-(void) Setimageurl: (Nsurl *) ImageURL2 {3_imageurl =ImageURL;4 //self.image = [UIImage imagewithdata:[nsdata DataWithContentsOfURL:self.imageURL]];5 [self startdownloadingimage];6 }7 8-(void) Startdownloadingimage9 {TenSelf.image =Nil; One if(self.imageurl) { A [Self.spinner startanimating]; -Nsurlrequest *request = [Nsurlrequest RequestWithURL:self.imageURL];//set the Request object -Nsurlsessionconfiguration *congiguration = [Nsurlsessionconfiguration ephemeralsessionconfiguration];//To set the request task configuration method theNsurlsession *session = [Nsurlsession sessionwithconfiguration:congiguration];//Defining URL Tasks -Nsurlsessiondownloadtask *task =[Session Downloadtaskwithrequest:request -completionhandler:^ (Nsurl *locationfile, Nsurlresponse *response, Nserror *error) { - if(!error) { + if([Request. URL IsEqual:self.imageURL]) { -UIImage *image =[UIImage imagewithdata:[nsdata datawithcontentsofurl:locationfile]; + //self.image = image; ADispatch_async (Dispatch_get_main_queue (), ^{ atSelf.image =image; -}); - //[Self performselectoronmainthread: @selector (setimage:) withobject:image Waituntildone:no]; - } - } - }]; // Define a thread task to invoke a network download in a child thread and invoke the display in the main thread of the downloaded successful picture in[Task resume];//Resume Task thread execution, the default is suspend when creating a task, need to restore to really execute - } to}
IOS7 Notes-10, multi-threaded, scrolling view