Uiscrollview rolling view-iOS development

Source: Internet
Author: User
Tags blank page
Statement

You are welcome to repost this article, but please respect the author's Labor achievements. repost this article and keep the statement in this box. Thank you.
ArticleSource: http://blog.csdn.net/iukey

The uiscrollview class is responsible for all uikit-based rolling operations.

I. Create

 
Cgrect bounds = [[uiscreen mainscreen] applicationframe]; uiscrollview * scrollview = [[uiscrollview alloc] initwithframe: bounds];

After creating a scroll view, you can bond the content of another view to a blank page of the scroll view. This creates a scrolling content window:

 
[Scrollview addsubview: myview];

You must provide the actual size of the content so that the scrolling view can know the rolling range:

 
Scrollview. contentsize = myview. Frame. size;

To enable the zoom function, you need to adjust the two attributes of the View: maxinumzoomscale
And mininumzoomscale. In this way, you can adjust the content size using the kneading gesture:

 
Scrollview. maxinumzoomscale = 2.0; // you can zoom in twice as much as scrollview. mininumzoomscale = 0.5; // you can zoom in to 0.5 times.

To enable the scaling function, you also need to add a uiscrollviewdelegate proxy to use

. This method returns the uiview object used for Scaling:

 
Scrollview. Delegate = self;-(uiview *) viewforzoominginscrollview :( uiscrollview *) scrollview {Retutn myview ;}

TIPS: for large-scale data, you may initially use a scaling ratio lower than the actual size (1.0), allowing users to smoothly zoom in.

Ii. Attributes

In addition to the scaling attribute used above, the scrolling view also allows you to adjust the behavior of actual content by adding other attributes. You can customize the uiscrollview class in multiple aspects. The following attributes are the most commonly used.

1. indicatorstyle

Specifies the type of the scroll bar indicator you want to use. The default action is to draw a black scroll bar in the white border, which is applicable to most backgrounds. Available style:

 
Uiscrollviewindicatorstyledefaultuiscrollviewindicatorstyleblackuiscrollviewindicatorstylewhite

2. contentoffset

A cgpoint structure that contains the offset of the content to be displayed relative to the upper left corner of the window. It starts from 0x0 by default, but you can also place the display content elsewhere.

3. directionallockenabled

The default behavior is to allow users to scroll horizontally and vertically at the same time. Setting this attribute to yes will lock the user's rolling behavior to allow only horizontal or vertical operations. The specific direction is determined by the initial attitude.

4. Bounces

When a user reaches the edge of the rolling area, this function allows the user to drag a little outside the border. After you release your finger, the area will return to the original position like a rubber band, giving the user a visible prompt, indicating that he has reached the start or end position of the document. If you do not want to allow the user to scroll beyond the visible content, you can set this attribute to No.

5. bounceszoom

Similar to the bounces option, This method allows the user to zoom beyond the maximum or minimum zoom level, and then play back to the range. If you do not want users to zoom out of the specified range, set this attribute to No.

6. pagingenabled

When the paging function is enabled, the scroll view is divided into multiple independent segments, and the scrolling experience of two users is changed to page flip. You can use this attribute to flip the page.

Iii. Delegation Method

You can assign a delegate to the rolling view. The following delegate methods will receive notifications at specific times.

 
-(Void) scrollviewdidscroll :( uiscrollview *) scrollview; // a notification is received when the view is rolled. Includes a pointer to the scrolling view, from which you can read the contentoffset attribute to determine the position to which it scrolls.

 
-(Void) scrollviewwillbegindragging :( uiscrollview *) scrollview; // you will be notified of the first time you drag in a certain direction. This method will get the scroll view pointer passed as the parameter, and can also read the contentoffset attribute from it.
 
-(Void) scrollviewdidenddragging :( uiscrollview *) scrollview willdecelerate :( bool) decelerate; // you will be notified when you drag your finger. You will also get a Boolean value indicating whether to slow down before the final position of the well-known report rolling view.
-(Void) scrollviewwillbegindecelerate :( uiscrollview *) scrollview; // you will receive a notification when you pull your finger and the view needs to move. This method can be used to read the contentoffset attribute to determine the final stop position of the scroll bar when the user raises his finger to the last rolling position.
 
-(Void) scrollviewdidenddecelerating :( uiscrollview *) scrollview; // you will be notified when the deceleration and rolling view mentioned above are stopped. When this notification is received, the contentoffset attribute of the scroll view reflects the position where the scroll bar stops.
 
-(Void) scrollviewdidendzooming :( uiscrollview *) scrollview withview :( uiview *) view atscale :( float) scale; // you will receive a notification when scaling the content. The zoom ratio is a floating point value and is passed as a parameter.
 
-(Bool) scrollviewshouldscrolltotop :( uiscrollview *) scrollview;-(void) scrollviewdidscrolltotop :( uiscrollview *) scrollview; // when the user clicks the iPhone status bar, the rolling view delegate determines whether the view is rolled back to the beginning.

OK. All of them are summarized. A page flip example will be written later.

Related Article

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.