Main content: Uiscrollview, Uipagecontrol (Use: Software introduction page, photo album ...) such as
First, Uiscrollview
Uiscrollview: Is a view that can be scrolled ( Note: UIView itself cannot scroll, subclass Uiscrollview extends the functionality of scrolling, Uiscrollview is the base class for all scrolling views )
The main expertise and two aspects:
1, scroll: Contentsize is greater than frame.size, can scroll
2, Zoom: With zoom, you can specify the zoom multiplier
Uiscrollview related properties for scrolling:
1, Contentsize: Defines the content area size, determines whether can slide
2. Contentoffset: Offset of the upper left corner of the view from the origin of the coordinates
3. Scrollstotop: Slide to the top (when sliding the scroll bar)
4, Pagingenable: Whether the whole page sliding
5, bounces: whether the border rebound
6. Scrollenable: Is it possible to scroll
7, Showshorizontalscrolllndicator: Control whether to show the horizontal direction of the scroll bar
8, Showsverticalscrolllndicator: Control whether to show the vertical direction of the scroll bar
9, Alwaysbouncehorizontal: Control horizontal direction encountered whether the border rebound
10, Alwaysbouncevertical: Control vertical direction to see if the frame bounces
Uiscrollview related properties for scaling
1, Minimumzoomscale: The minimum scale of scaling
2, Maximumzoomscale: magnification of the largest proportion
3, Zoomscale: Set the change ratio
4, zooming: to determine whether the scaling rebound
5, Bounceroom: control when the zoom will rebound
Note: To achieve scaling, you also need to implement delegate, which specifies who the zoomed view is
Uiscrollview Rolling Agent method
//scrolling will trigger
-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView
//triggers when dragging starts
-(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView
trigger at end of drag/pull
-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate
//start to slow down when triggered
-(void) scrollviewwillbegindecelerating: (Uiscrollview *) ScrollView
//end-of-deceleration trigger (when stopped)
-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView
Proxy methods for scaling:
//Complete zoom in and zoom out trigger
-(void) scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (float) scale
//Specifies that a Uiscrollview sub-view can be scaled down
-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView
Second, Uipagecontrol
Uipagecontrol: Used to indicate which page is currently, usually used in conjunction with Uiscrollview
Related properties:
CurrentPage: Current Page
Numberofpages: Specify the number of pages
Uipagecontrol can see from the class name that its parent class is Uicontrol, and all can add events to it like a button, except that the event trigger is no longer uicontroleventstouchupinside, But uicontroleventsvaluechanged.
Iii. examples of use of Uiscrollview and Uipagecontrol
//Create Uiscrollview Object
Uiscrollview *scrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (0, 0, Self.view.bounds.size.width, Self.view.bounds.size.height)];
//Add to view
[Self addsubview:scrollview];
//Set background color
Scrollview.background = [Uicolor Redcolor];
//Set the slide bar to display the horizontal
Self.showhorizontalscrollindicator = YES;
//Set the size of the content view
Scrollview.containsize = Cgsizemake (ScrollView.bounds.size.width * i, scrollView.bounds.size.height);//How many pictures, I is how much
//Set the full page slide of the picture
scrollview.pagingenabled = YES;
//Add images to Uiscrollview
for (int i = 0; i < count; i++) {
Uiimageview *imageview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "%d", I]];
//Set the size of the picture
Imageview.frame = CGRectMake ((i-1) * self.frame.size.width, 0, Self.frame.size.width, self.frame.size.height);
//Add to ScrollView
[ScrollView Addsubview:imageview];
//Release
[ImageView release], ImageView = nil;
}
//Add Page Controller
//Create Objects
Uipagecontroller *pagecontrol = [[[[Uipagecontroller alloc] init] autorelease];
//Set Location
Pagecontrol.frame = CGRectMake (0, self.view.frame.size.height-40, Self.view.frame.size.width, 30);
//Set the number of dots (pages)
Pagecontrol.numberofpages = 10;
//Set which dot is currently at
Pagecontrol.currentpage = 2;
//The color of the shop that is not selected
Pagecontrol.pageindicatortintcolor = [Uicolor Redcolor];
//Color of the current point point
Pagecontrol.currentpageindicatortintcolor = [Uicolor Bluecolor];
//Set Listener events
[Pagecontrol addtarget:self Action: @selector (pagecontrolaction:) forcontrolevents:uicontroleventvaluechanged];//
//Add to view
[Self.view Addsubview:pagecontrol];
#pragma mark-implementing-pagecontrolaction: Monitoring Events
-(void) Pagecontrolaction: (Uipagecontrol *) Sender {
//enable Uiscrollview to make corresponding slide display
Cgsize viewsize = _userguidescrollview.frame.size;
CGRect rect = CGRectMake (sender.currentpage * viewsize.width, 0, Viewsize.width, viewsize.height);
[_userguidescrollview Scrollrecttovisible:rect Animated:yes];
}
#pragma mark-Override the Proxy method in----scrollviewdelegate to implement sliding
-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView {
//Calculate offset
int index = ABS (scrollview.contentoffset.x/scrollview.frame.size.width);
//Set Pagecontrol according to offset
_scrollpagecontrol.currentpage = index;
}
#pragma mark-Override----Dealloc method
-(void) Dealloc {
//Release properties of memory
[_scrollpagecontrol release], _scrollpagecontrol = nil;
[_userguidescrollview release], _userguidescrollview = nil;
//Call the Dealloc method of the parent class
[Super Dealloc];
}
UI Seventh Lesson