IOS7 Notes-10, multi-threaded, scrolling view

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.