Ios-scroll view (UIScrollView) details, iosuiscrollview
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 size of the scrolling view.
Create a rolling view instance:
- (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(1000, 1000); sv.backgroundColor = [UIColor redColor]; [self.view addSubview:sv];}
:
-(Void) setZoomScale :( CGFloat) scale animated :( BOOL) animated Merge (3_0);-(void) zoomToRect :( CGRect) rect animated :( BOOL) animated Merge (3_0 );
SetZoomScale: animated: proportional Scaling
ZoomToRect: animated: scale the size of the given rectangle
4. Delegate
UIScrollViewDelegate can receive a large number of messages. This helps you track the work of the rolling view.
The following is the definition of the Protocol.
@protocol UIScrollViewDelegate<NSObject>@optional- (void)scrollViewDidScroll:(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)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0);// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; // called on finger up as we are moving- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; // called when scroll view grinds to a halt- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView; // called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating- (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 *)view 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
The meaning of these methods is not explained. The fastest way to learn with annotations is to read these header files.