iOS Development UI Chapter-uiscrollview Controls Introduction
First, the knowledge point simple introduction
What is a 1.UIScrollView control?
(1) The screen of the mobile device? Small is extremely limited, so direct exhibition, the content of the user's eyes is also very limited
(2) When the exhibition shows more content than a screen, the user can scroll through gestures to see what's outside of the screen
(3) Ordinary UIView does not have scrolling function, can not display too much content
(4) Uiscrollview is a scrollable view control that can be used to show a lot of content, and can scroll to see all the content
(5) Example: "Settings" on the phone, other? Sample programs
Simple use of 2.UIScrollView
(1) Add the content that needs to show to Uiscrollview
(2) Set the Contentsize property of the Uiscrollview, tell Uiscrollview all the contents of the ruler, that is, to tell it the range of scrolling (how far to roll, where to roll to the end)
3. Properties
(1) Common properties:
1) @property (nonatomic) Cgpointcontentoffset; This property is used to display uiscrollview scrolling position
2) @property (nonatomic) cgsizecontentsize; This property is used to uiscrollview the contents of the table, scroll range (how far to roll)
3) @property (nonatomic) Uiedgeinsetscontentinset; This property is capable of adding additional scrolling areas for 4 weeks of Uiscrollview
(2) Other properties:
1) @property (nonatomic) BOOL bounces; Set Uiscrollview If spring effect is required
2) @property (nonatomic,getter=isscrollenabled) boolscrollenabled; Sets whether Uiscrollview can scroll
3) @property (nonatomic) BOOL showshorizontalscrollindicator; Do you have a display? Horizontal scroll bar
4) @property (nonatomic) BOOL showsverticalscrollindicator; Do you want to show the vertical scroll bar?
4. Attention Points
• If Uiscrollview cannot scroll, the following may be the reason:
(1) No setup contentsize
(2) scrollenabled = NO
(3) No Touch event Received: userinteractionenabled = no
(4) No cancellation of AutoLayout function (if you want to scrollview scrolling, you must cancel AutoLayout)
Ii. some notes on common properties of Uiscrollview
1. Examples of code used by attributes
1 #import "MJViewController.h" 2 3 @interfaceMjviewcontroller ()4 { 5 //Create a property in a private extension 6Uiscrollview *_scrollview;7 } 8 @end 9 Ten @implementationMjviewcontroller One A- (void) Viewdidload - { -[Super Viewdidload]; the - //1. Create Uiscrollview -Uiscrollview *scrollview =[[Uiscrollview alloc] init]; -Scrollview.frame = CGRectMake (0,0, -, -);//size in frame refers to the visual range of the Uiscrollview +Scrollview.backgroundcolor =[Uicolor Graycolor]; -[Self.view Addsubview:scrollview]; + A //2. Create Uiimageview (image) atUiimageview *imageview =[[Uiimageview alloc] init]; -Imageview.image = [UIImage imagenamed:@"big.jpg"]; -CGFloat IMGW = imageView.image.size.width;//the width of the picture -CGFloat imgh = imageView.image.size.height;//the height of the picture -Imageview.frame = CGRectMake (0,0, IMGW, IMGH); -[ScrollView Addsubview:imageview]; in - //3. Setting the properties of the ScrollView to + //Sets the scrolling range (content size) of the Uiscrollview -Scrollview.contentsize =imageView.image.size; the * //Hide horizontal scroll bar $Scrollview.showshorizontalscrollindicator =NO;Panax NotoginsengScrollview.showsverticalscrollindicator =NO; - the //used to record the location of ScrollView scrolling + //Scrollview.contentoffset =; A the //Remove the Spring effect + //scrollview.bounces = NO; - $ //Add extra scrolling area (counterclockwise, up, left, bottom, right) $ //top left Bottom right -Scrollview.contentinset = Uiedgeinsetsmake ( -, -, -, -); - the_scrollview =ScrollView; - }Wuyi the-(Ibaction) Down: (UIButton *) Sender { -[UIView animatewithduration:1.0animations:^{ Wu //Three steps -Cgpoint offset =_scrollview.contentoffset; AboutOffset.y + = Max; $_scrollview.contentoffset =offset; - - //_scrollview.contentoffset = cgpointmake (0, 0); - }]; A } + @end
2. Several attribute coordinates
3. Important Notes
(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?
Iii. Some of the helpful understanding
Model Diagram:
Comparison chart:
Coordinate chart:
iOS Development UI Chapter-uiscrollview controls Introduction