Use of IOS Uiscrollview

Source: Internet
Author: User

First, why use Uiscrollview?

The screen size of mobile devices is extremely limited, so the content displayed directly in front of the user is also quite limited
When more content is displayed than a screen, users can scroll to see what's outside of the screen
The normal UIView does not have scrolling capability and is not suitable for displaying too much content.


Uiscrollview is a scroll-capable view control that can be used to display a large amount of content, and can be scrolled to see all the content

The system setup is a ScrollView:

Second, basic use:

Add what you need to show to Uiscrollview
Set the Contentsize property of the Uiscrollview to tell Uiscrollview all the dimensions of the content, that is, to tell it the range of scrolling (how far to roll, where to roll to the end)

Common Properties:

@property (nonatomic)         cgpoint                      contentoffset;                  // default Cgpointzero@property (nonatomic)         cgsize                       contentsize;                    // default Cgsizezero@property (nonatomic)         uiedgeinsets                 contentinset;                   // default Uiedgeinsetszero. Add additional scroll area around content
Contentoffset: This property is used to indicate the position of the Uiscrollview scroll (in fact, the upper left corner of the content and the upper left corner of the ScrollView value)
Contentsize: This property is used to indicate the size of the Uiscrollview content, the scrolling range (how far to roll)
Contentinset: This property can add additional scrolling areas for 4 weeks of uiscrollview, generally to avoid scrollview content being blocked by other controls

Other properties:

@property (nonatomic) BOOL bounces;
Set Uiscrollview If spring effect is required

@property (nonatomic,getter=isscrollenabled) BOOL scrollenabled;
Sets whether Uiscrollview can scroll

@property (nonatomic) BOOL showshorizontalscrollindicator;
Whether to display the horizontal scroll bar

@property (nonatomic) BOOL showsverticalscrollindicator;
Whether to show vertical scroll bars

Third, the agent of Uiscrollview

When Uiscrollview a series of scrolling operations, it will automatically notify its agent (delegate) object, send the corresponding message to its agent, let the agent know its scrolling situation. So to listen to the Uiscrollview scrolling process, you must first set up a proxy object Uiscrollview, and then through the agent to know the Uiscrollview scrolling process.

Common methods of Uiscrollviewdelegate protocol:
// called when the user starts dragging -(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView; // called when scrolling to a location -(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView; // call when user ends drag -(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate;

Implementation of Scaling:

Set id<uiscrollviewdelegate> delegate proxy object for Uiscrollview
Set Minimumzoomscale: Minimum scale to zoom out
Set Maximumzoomscale: Maximum scale magnification
Let the proxy object implement the following method to return the view control that needs to be scaled
-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView;

Other proxy methods related to scaling:

// when zoom is complete call -(void) scrollviewwillbeginzooming: (Uiscrollview *) ScrollView Withview: (UIView *) View// zoom in Call -(void) Scrollviewdidzoom: (Uiscrollview *) ScrollView

Paging:
//as long as the Pageenabled property of the Uiscrollview is set to Yes,uiscrollview will be split into separate pages, the contents can be paginated//generally with uipagecontrol enhance the paging effect, Uipagecontrol commonly used properties as followsaltogether how many pages @property (nonatomic) Nsinteger numberofpages;//the page number that is currently displayed@property (nonatomic) Nsinteger currentpage;//Whether you need to hide the page number indicator when there is only one page@property (nonatomic) BOOL hidesforsinglepage;//Color of other page number indicators@property (nonatomic,retain) Uicolor *Pageindicatortintcolor;//color of the current page number indicator@property (Nonatomic,retain) Uicolor *currentpageindicatortintcolor;

Use of IOS 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.