ScrollView View analysis of columns

Source: Internet
Author: User

The Code Essence section is as follows:

//1. Add ScrollView /*1). Add a ScrollView;    2). Create a focus, hot, nearby three controllers.    3). Store their names in the array, traverse and place them into the controller.    4). Set the contentsize of the ScrollView.    5). Set the offset of the scrollview. 6). Called when the Stop animation method is set to the current ScrollView. (should be the way to stop dragging)*/Nsarray*controls = @[@"Strfollowviewcontroller",@"Strhotviewcontroller",@"Strnearviewcontroller"];  for(Nsinteger i =0; i < Controls.Count; i++) {Uiviewcontroller*VC =[[Nsclassfromstring (Controls[i]) alloc] init]; Vc.title=Self.titlenames[i];    [Self ADDCHILDVIEWCONTROLLER:VC]; } self. Mainscrollview.contentsize= Cgsizemake (Self.titleNames.count *[uiscreen mainscreen].bounds.size.width,0); Self. Mainscrollview.contentoffset= Cgpointmake (Screen_width,0); [Self scrollviewdidenddecelerating:self. Mainscrollview];}//2. Setting up the agent#pragmaMark Scrollviewdelegate-(void) Scrollviewdidenddecelerating: (Uiscrollview *) scrollview{[self Scrollviewdidendscrollinganimation:scrollview];}- (void) Scrollviewdidendscrollinganimation: (Uiscrollview *) scrollview{/** 1. Get the width and height, also open the paging function 2. Gets the index value. 3. Set the offset 4. Set the Viewframe to not return 5 if it has not been loaded again. Adding a sub-controller view to ScrollView*/Nsinteger Width=Screen_width; Nsinteger Height=Screen_height; CGFloat OffsetX=Scrollview.contentoffset.x; Nsinteger Index= offsetx/width;    [Self.topview Topviewwithindex:index]; Uiviewcontroller*VC =Self.childviewcontrollers[index]; if([VC isviewloaded])return; Vc.view.frame= CGRectMake (OffsetX,0, width, height); [Self. Mainscrollview AddSubview:vc.view];}//3. Add TopView-(Strtopview *) topview{if(!_topview) {_topview= [[Strtopview alloc] Initwithframe:cgrectmake (0,0, $, -) TitleNames:self.titleNames tagblock:^(Nsinteger index) {[Self. Mainscrollview Setcontentoffset:cgpointmake (Index*screen_width,0) Animated:yes];    }]; }    return_topview;}

ScrollView View analysis of columns

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.