ios– scrolling View (Uiscrollview) detailed

Source: Internet
Author: User

Mobile devices have a limited screen size, and when a view is displayed larger than the screen size, a scrolling view is used, such as the content of a Web page is usually larger than the screen size, and the browser uses a scrolling view.

Uiscrollview has a contentsize attribute, declared as follows:

@property (nonatomic)         cgsize                       contentsize;

This property indicates how large the content of the scrolling view is.

To create a scrolling view instance:

-(void) viewdidload {    [super Viewdidload];     // additional setup after loading the view, typically from a nib.    Uiscrollview *SV = [[Uiscrollview alloc] initWithFrame:self.view.frame];     = Cgsizemake (+);     = [Uicolor redcolor];    [Self.view ADDSUBVIEW:SV];}

:

The Contentsize property is {1000,1000}, and you can see the horizontal and vertical scroll bars clearly.

1. Scrolling

The scroll of the view is nothing to say, mainly to set some properties:


Scrollenabled whether to turn on scrolling

Scrollstotop default to Yes, users can click the status bar to scroll to the top

Bounces defaults to Yes, which can be scrolled further when scrolling to the boundary, and quickly bouncing back to the original position when released

directionallockenabled If yes, you can only scroll in one Direction at a time

Decelerationrate after the flick of the screen, the speed of the scroll gradually decays, the lower the value of the faster decay

Showshorizontalscrollindicator, showsverticalscrollindicator default is yes, scroll indicator bar is visible when scrolling

Indicatorstyle the style of the scroll bar (Uiscrollviewindicatorstyleblack, Uiscrollviewindicatorstyledefaultuiscrollviewindicatorstylewhite)

Contentinset the margin of the specified content for four weeks (the order of top left and bottom right)

SCROLLINDICATORINSETS Specifies the toggle of the scroll indicator bar in position

Contentoffset The anchor point of the content, the upper-left corner of the current display

2. Paging

When the content is larger than the screen can be paged, set the Pagingenabled property is Yes, scrolling view does not allow users to slide freely, only by sliding to adjacent parts.

3. Zooming

Enables scrolling views to scale when required to set the values of the Minimumzoomscale and Maximumzoomscale two properties (by default, 1), and also to implement Viewforzoominginscrollview in a delegate of the scrolling view: method, This method returns which child view in the scrolling view is scalable, and if the scrolling view has more than one child view, but usually we need to scale the contents of the entire scrolling view, then place multiple views in a single view, making this view a sub-view of the scrolling view.

The scrolling view is scaled by the response to the pinch gesture, and if the zoom exceeds the limit we set, the dimension is returned to the limit we set when the gesture ends. If you want to strictly limit the scale to no more than the limit we set, set the Bounceszoom to No.

In some cases, such as when we double-click to zoom, we need to zoom in code, using the following two methods:

-(void) Setzoomscale: (cgfloat) scale animated: (BOOL) animated Ns_available_ios (3_0); -(void) Zoomtorect: (cgrect) Rect animated: (BOOL) animated Ns_available_ios (3_0);

Setzoomscale:animated: Scaling by scale

Zoomtorect:animated: The size of the given rectangle is scaled

4. Delegation

Uiscrollviewdelegate can receive a large number of messages open to help you track the scrolling view of work

Here is the definition of the Protocol

@protocolUiscrollviewdelegate<nsobject>@optional- (void) Scrollviewdidscroll: (Uiscrollview *) ScrollView;//Any offset changes- (void) Scrollviewdidzoom: (Uiscrollview *) ScrollView Ns_available_ios (3_2);//Any zoom changes//called on start of dragging (could require some time and or distance to move)- (void) Scrollviewwillbegindragging: (Uiscrollview *) ScrollView;//called on finger up if the user dragged. Velocity was in Points/millisecond. Targetcontentoffset could be changed to adj UST where the scroll view comes to rest- (void) Scrollviewwillenddragging: (Uiscrollview *) ScrollView withvelocity: (cgpoint) Velocity targetcontentoffset: (inout Cgpoint *) Targetcontentoffset Ns_available_ios (5_0);//called on finger up if the user dragged. Decelerate is true if it'll continue moving afterwards- (void) Scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate;- (void) Scrollviewwillbegindecelerating: (Uiscrollview *) ScrollView;//called on finger up as we are moving- (void) Scrollviewdidenddecelerating: (Uiscrollview *) ScrollView;//called when scroll view grinds to a halt- (void) Scrollviewdidendscrollinganimation: (Uiscrollview *) ScrollView;//called when setcontentoffset/scrollrectvisible:animated:finishes. Not called if not animating-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView;//return a view that would be scaled. If delegate returns nil, nothing happens- (void) Scrollviewwillbeginzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Ns_available_ios (3_2);//called before the scroll view begins zooming its content- (void) Scrollviewdidendzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View Atscale: (cgfloat) scale;//Scale between minimum and maximum. Called after any ' bounce ' animations-(BOOL) Scrollviewshouldscrolltotop: (Uiscrollview *) ScrollView;//return a Yes if you want to scroll to the top. If not defined, assumes Yes- (void) Scrollviewdidscrolltotop: (Uiscrollview *) ScrollView;//called when scrolling animation finished. is called immediately if already at top@end

The meaning of these methods is not explained, annotated, the fastest way to learn is to look at these header files.

ios– scrolling View (Uiscrollview) detailed

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.