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 );