Detailed description of ios-scroll view (UIScrollView)

Source: Internet
Author: User

Detailed description of ios-scroll view (UIScrollView)
The screen size of a mobile device is limited. When the content displayed in a view is larger than the screen size, a rolling view is used. For example, the content of a webpage is usually larger than the screen size, then the browser uses the scroll view. UIScrollView has a contentSize attribute, which is declared as follows: @ property (nonatomic) CGSize contentSize; this attribute indicates the content of the rolling view. Create a rolling view instance: copy the code-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIScrollView * sv = [[UIScrollView alloc] initWithFrame: self. view. frame]; sv. contentSize = CGSizeMake (0, 1000,100); sv. backgroundColor = [UIColor redColor]; [self. view addSubview: sv];} copy the code: image contentSize attribute is {}, you can see the horizontal and vertical scroll bars. 1. there is nothing to say about rolling a rolling view. It mainly sets some attributes: whether scrollEnabled enables rolling. The default value of scrollsToTop is YES. You can click the status bar to scroll to the top of the bounces. The default value is YES, when you scroll to the boundary, you can scroll back to the original directionalLockEnabled. If YES, you can scroll to decelerationRate in one direction at the same time. After the screen is played lightly, the scrolling speed gradually degrades, showsHorizontalScrollIndicator, showsVerticalScrollIndicator: YES by default. When scrolling, the scroll indicator bar shows the style of the indicatorStyle scroll bar (UIScrollViewIndicatorStyleBlack, skip RStyleWhite) contentInset specifies the margin around the content (the order of the top left and bottom right) scrollIndicatorInsets specifies the position for switching the contentOffset content of the scroll indicator bar in the position. Currently, 2 is displayed in the upper left corner. when the page content is greater than the screen content, you can page by page. If the pagingEnabled attribute is set to YES, the scroll view does not allow users to slide freely, but can only slide to adjacent parts. 3. zoominginscrollview: method, this method returns the child view in the scroll view that can be scaled. If the scroll view has multiple child views, we usually need to scale the content of the entire scroll view, you can place multiple views in one view and convert the view into a subview of a rolling view. The scroll view scales the response of the kneading gesture. If the scaling exceeds the limit set, the size will return to the limit set when the gesture ends. If you want to strictly limit the zooming to NO more than we set, set bouncesZoom to NO. In some cases, for example, when we double-click a scaling task, we need to use code to scale the task. The following two methods are used:-(void) setZoomScale :( CGFloat) scale animated :( BOOL) animated scaled (3_0);-(void) zoomToRect :( CGRect) rect animated :( BOOL) animated scaled (3_0); setZoomScale: animated: zoomToRect: animated: scale the size of the given rectangle 4. entrust UIScrollViewDelegate to receive a large number of messages. To help you track the rolling view, the following is the protocol definition copy code @ protocol UIScrollViewDelegate <NSObject> @ optional-(void) scrollViewDidS Croll :( UIScrollView *) scrollView; // any offset changes-(void) scrollViewDidZoom :( UIScrollView *) scrollView NS_AVAILABLE_IOS (3_2 ); // any zoom scale changes // called on start of dragging (may require some time and or distance to move)-(void) scrollViewWillBeginDragging :( UIScrollView *) scrollView; // called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may Be changed to adjust where the scroll view comes to rest-(void) values :( UIScrollView *) scrollView withVelocity :( CGPoint) velocity targetContentOffset :( inout CGPoint *) targetContentOffset values (5_0 ); // called on finger up if the user dragged. decelerate is true if it will continue moving afterwards-(void) scrollViewDidEndDragging :( UIScrollView *) scrollView willDecelera Te :( BOOL) decelerate;-(void) rollback :( UIScrollView *) scrollView; // called on finger up as we are moving-(void) scrollViewDidEndDecelerating :( UIScrollView *) scrollView; // called when scroll view grinds to a halt-(void) preview :( UIScrollView *) scrollView; // called when setContentOffset/scrollRectVisible: animated: finishes. not called if not anim Ating-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView; // return a view that will 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 *) vie W 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. may be called immediately if already at top @ end copy code The meaning of these methods is not explained. The fastest way to learn with annotations is to read these header files.

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.