iOS Basics (15) Basic usage of--uiscrollview

Source: Internet
Author: User

A scrolling view (Uiscrollview) is typically used to display a view with a larger content size than the screen size.

first, the basic properties

1, cgsize contentsize: Set the scroll range of the Uiscrollview

2, Cgpoint Contentoffset:uiscrollview the position of the current scroll

3. Uiedgeinsets Contentinset: Set the edge of the content

4. BOOL bounces indicates whether it can bounce when out of bounds

5, BOOL scrollenabled whether can scroll

6, BOOL Showshorizontalscrollindicator whether to show the horizontal direction of the scroll bar

7, BOOL Showsverticalscrollindicator whether to display the vertical direction of the scroll bar

8, Uiscrollviewindicatorstyle Indicatorstyle set the style of the scroll bar

9, BOOL Tracking monitor whether the current target is being tracked

10, BOOL dragging monitor whether the current target is being dragged

11, BOOL decelerating Monitor whether the current target is slowing down

12, BOOL zooming determine whether the size of the control is changing

13, BOOL zoombouncing determine whether the scaling rebound

14, Minimumzoomscale reduction of the minimum proportion

15, Maximumzoomscale magnification of the largest proportion

16, BOOL Scrollstotop When you click on the device's status bar, the control is Scrollstotop = yes scroll back to the top

1 //Initialize, set size and size2ScrollView = [[Uiscrollview alloc] initWithFrame: (cgrect) {0,0, frame.size.width,frame.size.height}];3 //Add to view4 [Self.view Addsubview:scrollview];5 //Background Color6Scrollview.backgroundcolor =[Uicolor Orangecolor];7 //Scrolling Range8Scrollview.contentsize = Cgsizemake (frame.size.width+ -, frame.size.height+ $);9 //Set up proxyTenScrollView.Delegate=Self ; One //whether to split page Ascrollview.pagingenabled =YES; - //whether to scroll -scrollview.scrollenabled =YES; the //whether scroll bars are displayed -Scrollview.showshorizontalscrollindicator =YES; -Scrollview.showsverticalscrollindicator =NO; - //scroll bar style +Scrollview.indicatorstyle =Uiscrollviewindicatorstylewhite; - //content edges and indicator edges +Scrollview.contentinset = Uiedgeinsetsmake (0, -, -, -); AScrollview.scrollindicatorinsets = Uiedgeinsetsmake (0, -,0,0);
Ii. Common Methods

1. Returns a zoomed-in or zoomed-out view

-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView;

2, start to zoom in or zoom out

-(void) scrollviewwillbeginzooming: (Uiscrollview *) ScrollView Withview: (UIView *) view;

3. At the end of zoom

-(void) scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (float) scale;

4. The view has been enlarged or shrunk

-(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView;

5, whether to support sliding to the top of

-(BOOL) Scrollviewshouldscrolltotop: (Uiscrollview *) ScrollView;

6. Call this method when sliding to the top

-(void) Scrollviewdidscrolltotop: (Uiscrollview *) ScrollView;

7, ScrollView has been sliding

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView;

8. ScrollView Start dragging

-(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView;

9. ScrollView End Drag

-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate;

10, ScrollView began to slow down

-(void) scrollviewwillbegindecelerating: (Uiscrollview *) ScrollView;

11, ScrollView deceleration stop

-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView;

three, Uiscrollview and Uipagecontrol to achieve picture switching

Let's start with a brief introduction to the Uipagecontrol:

Uipagecontroll is an iOS system UI control that inherits from Uicontrol and can provide developers with the ability to design paging effects.

1     //Initialize2Pagectrl=[[uipagecontrol Alloc] Initwithframe:cgrectmake (0, the,375, -)];3 [Self.view Addsubview:pagectrl];4     //set Number of controller pages (default = 0)5pagectrl.numberofpages=3;6     //set the page number that is currently located7Pagectrl.currentpage =1;8     //sets whether the controller is automatically hidden when the total number of pages is 1 o'clock9Pagectrl.hidesforsinglepage =YES;Ten     //set the Controller page point color OnePagectrl.pageindicatortintcolor =[Uicolor Orangecolor]; A     //sets the color of the page point where the controller is currently located -Pagectrl.currentpageindicatortintcolor =[Uicolor Greencolor]; -pagectrl.tag= -; the      -     //Add a Click event to Pagecontrol - [PageCtrl addtarget:self Action: @selector (turnpage:) forcontrolevents:uicontroleventtouchupinside]; -     

View loading:

1 @interfaceViewcontroller () <UIScrollViewDelegate>{2     3Uiscrollview *ScrollView;4Uipagecontrol *PageCtrl;5     6Nsarray *Imagearray;7 8 }9 Ten @end One  A @implementationViewcontroller -  -- (void) Viewdidload { the [Super Viewdidload]; -     //additional setup after loading the view, typically from a nib. -      -     //Initialize +ScrollView = [[Uiscrollview alloc] initWithFrame: (cgrect) {0, -, self.view.frame.size.width,self.view.frame.size.height}]; - [Self.view Addsubview:scrollview]; +     //Agent AScrollView.Delegate=Self ; at     //Sliding Range -Scrollview.contentsize = Cgsizemake (375*3, the); -     //Background Color -Scrollview.backgroundcolor =[Uicolor Clearcolor]; -     //whether to split page -scrollview.pagingenabled =YES; in     //whether scroll bars are displayed -Scrollview.showshorizontalscrollindicator =NO; toScrollview.showsverticalscrollindicator =NO; +      -     //Image Array theImagearray = @[@"u=1522827729,398642494&fm=21&gp=0",@"u=498354980,1967037110&fm=21&gp=0",@"u=455056084,2054881807&fm=21&gp=0"]; *      $     //Loading PicturesPanax Notoginseng      for(intI=0; i<3; i++) { -Uiimageview *imageview=[[uiimageview alloc] Initwithframe:cgrectmake (i*375,0,375, the)]; the         //imageview.image=[uiimage imagenamed:[nsstring stringwithformat:@ "Image%d.jpg", I+1]]; +NSString *image =[Imagearray objectatindex:i]; AImageview.image =[UIImage imagenamed:image]; the          + [ScrollView Addsubview:imageview]; -  $     } $     //Initialize -Pagectrl=[[uipagecontrol Alloc] Initwithframe:cgrectmake (0, the,375, -)]; - [Self.view Addsubview:pagectrl]; the     //set Number of controller pages (default = 0) -pagectrl.numberofpages=3;Wuyi     //set the page number that is currently located thePagectrl.currentpage =1; -     //sets whether the controller is automatically hidden when the total number of pages is 1 o'clock WuPagectrl.hidesforsinglepage =YES; -     //set the Controller page point color AboutPagectrl.pageindicatortintcolor =[Uicolor Orangecolor]; $     //sets the color of the page point where the controller is currently located -Pagectrl.currentpageindicatortintcolor =[Uicolor Greencolor]; -pagectrl.tag= -; -      A     //Add a Click event to Pagecontrol + [PageCtrl addtarget:self Action: @selector (turnpage:) forcontrolevents:uicontroleventtouchupinside]; the      -}

Picture Toggle:

1 //uiscrollviewdelegate The scrollviewdidenddecelerating function, the user slides the page to stop and call the function2- (void) Scrollviewwillbegindecelerating: (Uiscrollview *) ScrollView3 {4     //update the current page of Uipagecontrol5     intcurrent=scrollview.contentoffset.x/ScrollView.frame.size.width;6NSLog (@"ScrollView:%f", scrollview.contentoffset.x);7Uipagecontrol *pagecontrol = (uipagecontrol*) [Self.view Viewwithtag: -];8Pagecontrol.currentpage =Current ;9     Ten } One  A //When you click Uipagecontrol, the response function Turnpage -- (void) Turnpage: (uipagecontrol*) change{ -     ///makes the Uiscrollview to make the corresponding slide display theCgsize size =scrollView.frame.size; -CGRect rect = (cgrect) {change.currentpage*size.width,0, size.width,size.height}; - [ScrollView scrollrecttovisible:rect animated:yes]; -  +}

iOS Basics (15) Basic usage of--uiscrollview

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.