The end of the love paper-----iOS learning Uiscrollview

Source: Internet
Author: User

A simple introduction to Uiscrolllview controls

1. What is Uiscrollview

(1) The screen size of mobile devices is extremely limited, so the content directly displayed in front of the user is also very limited

(2) When the content of the display is more than one screen, the user can scroll gestures to see what is outside the screen

(3) Normal UIView does not have scrolling function and cannot display too much content.

(4) Uiscrollview is a scroll-capable view control that can be used to display a large amount of content and can scroll through all the content

(5) Example: "Settings" on the phone, other sample programs

A simple way to use 2.UIScrollView

(1) Add the content that needs to be displayed to Uiscrollview

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

Common Properties of 3.UIScrollView

Cgpoint Contentoffset Monitor the position of the current control scroll
Cgsize contentsize The size of the scrolling range
Uiedgeinserts Contentinsert Set the perimeter margin of the ScrollView
Id<uiscrollerviewdelagate>delagate Set up protocols
BOOL Showshorizontalscrollindicator Controls whether to display scroll bars in the horizontal direction
BOOL Showsverticalscrollindicator Controls whether to display scroll bars in a vertical direction
Float Minimumzoomscale Minimum scale to shrink
Float Maximumzoomscale Maximum scale of magnification
BOOL Bounceszoom Controls whether the zoom will bounce

4. Several common properties

5. If you cannot scroll, there may be the following reasons

♥ Not set Contentsize

♥scrollenable = NO

♥ No touch events Received: userinteractionenabled = no

♥ did not cancel the AutoLayout function (temporarily do not know if not cancel this there is no other way Yes)

6. Places that are prone to misunderstanding

(1) Uiscrollview frame and Contentsize attribute: Uiscrollview frame refers to the visual range of this ScrollView (visible area), Contentsize is its scroll range.

(2) Contentinset (usually not a struct is an enumeration), adding additional scrolling areas to the Uiscrollview. (Top, left, bottom, right) counterclockwise. Contentinset can be set using code or a view controller, but the two are different (note the distinction).

(3) The Contentsize property can only be set with code.

(4) Contentoffset is a cgpoint-type structure used to record the scroll position of the ScrollView, which is where the "box" is recorded. Knowing this property, you know where it is, and you can control the movement of the "box" by setting this property.

(5) It is not allowed to directly modify the members of an object's internal structure properties, three steps (get the value, modify it, and then assign the modified value back).

(6) Where is the origin of the Contentoffset when additional areas are added? is actually not included in the extra area.

Second, the agent of Uiscrollview (delegate)

♦ A lot of times, we want to do some specific things when uiscrollview is scrolling or scrolling to a location or stops scrolling♦ To complete the above functions, the precondition is to be able to monitor the entire rolling process of Uiscrollview♦ When uiscrollview a series of scrolling operation, it will automatically notify its agent (delegate) object, send the corresponding message to its agent, let the agent know its scrolling situationIn other words, to listen to the Uiscrollview scrolling process, you must first set up a proxy object for Uiscrollview, and then through the agent to know the Uiscrollview scrolling processNote: To become a Uiscrollview delegate, is conditional, must abide by the corresponding protocol, to achieve the corresponding method to monitor the Uiscrollview rolling process three, Uiscrollview control to achieve picture scaling1. About zoomingThere are times when we might want to zoom in on some content, such asUiscrollview not only scrolls through a large amount of content, but also scales its contents. That is, to complete the zoom function, simply add the content that needs to be scaled to the Uiscrollview,2. Scaling principlewhen the user uses a pinch gesture on Uiscrollview, Uiscrollview sends a message to the agent asking the agent to zoom in on which child control (which piece of content) it is inside.when the user uses the pinch gesture on Uiscrollview, Uiscrollview invokes the proxy's Viewforzoominginscrollview: method, which is the control that the method returns is the one that needs to be scaled. 3. Implement the Zoom function(1) Controller Compliance Agent Agreement <UIScrollView>(2) Set up Agent(3) Calling the Proxy method, returning the child controls that need to implement the zoom function(4) Set the zoom range (max and min scale)
1 //when the user starts using the pinch gesture2-(UIView *) Viewforzoominginscrolllview: (Uiscrollview *) ScrollView3 {4 //The returned control is the one that needs to be scaled5 returnSelf.mimoview;//Mimoview Control has been set to a property6 }7 8 9 //using pinch gesturesTen-(void) Scrollviewdidzoom: (Uiscrollview *) scrollview{ One}

A little bit of notes, good night

The end of the love paper-----iOS learning 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.