Ios ui rolling view UIScrollView learning notes and continuous updates of various effects

Source: Internet
Author: User

UIScrollView common attributes

ScrollView. maximumZoomScale = 2.0; // maximum scaling ratio

ScrollView. minimumZoomScale = 0.2; // minimum scale

ScrollView. contentSize = self. view. frame. size + 10; // you can specify the content size.

ScrollView. pagingEnabled = YES; // NO

ScrollView. scrollEnabled = YES; // The default value is YES if scroll is allowed.

Common UIScrollView Methods

-(Void) scrollViewDidScroll :( UIScrollView *) scrollView; // scrollview is called when every offset is scrolled.

-(Void) scrollViewWillBeginDragging :( UIScrollView *) scrollView; // call the scrollview when it is dragged.

-(Void) scrollViewDidEndDragging :( UIScrollView *) scrollView willDecelerate :( BOOL) decelerate // called when scrollview ends dragging


UIScrollView cannot be rolled

Check

1. The contentSize is not set.

2. the storyboard autolayout is not canceled.


UIScrollView Effects

1. Penetration effect + drag the image to display content

// You must first set the content size of the ScrollView to be able to drag or scroll the view.

// ScrollView content size = visible size of the current imageView

// The size of the frame is based on the size of the parent control. Therefore, this effect must be effective only when the width of the imageView is higher than the width and height of the view.

Self. scrollView. contentSize = self. imageView. frame. size; // after this setting, you can scroll ScrollView and drag the image.

// ContentInset achieves the penetration effect mainly by inserting the content = Insert the content above 64 Insert the left without inserting the bottom insert 44 Insert the right without adding the ContentSize scroll size

Self. scrollView. contentInset = UIEdgeInsetsMake (64, 0, 44,0 );

// The upward offset of ConntentOffset relative to frame. y, that is, the point in the upper left corner of the current scroll axis

Self. scrollView. contentOffset = CGPointMake (0,-64 );


2. Paging Effect

Self. scrollView. delegate = self;

For (int I = 0; I <3; I ++)

{

UIView * view = [[UIViewalloc] init];

// Set the x coordinates of the I-th view.

View. frame = CGRectMake (I * [UIScreenmainScreen]. bounds. size. width, 0, self. view. frame. size. width, self. view. frame. size. height );

Int red = arc4random (); // random color

Int green = arc4random ();

Int blue = arc4random ();

View. backgroundColor = [UIColorcolorWithRed: red/230.0 green: green/150.0 blue: blue/30.0 alpha: 1];

[Self. scrollViewaddSubview: view];

}

// Set the scrollview content size

Self. scrollView. contentSize = CGSizeMake (3 * (self. view. frame. size. width), self. view. frame. size. height );

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.