缩放相关
//设置拉伸形变的最大倍数和最小倍数
scrollView.maximumZoomScale = 2.0;
scrollView.minimumZoomScale = 0.2;
// 返回一个放大或者缩小的视图,比如返回一个UIImageView;则该view可以实现拉伸变形。
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
// 开始放大或者缩小
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view;
// 缩放结束时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale ;
// 视图已经放大或缩小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView ;
//scrollView是否开始拉伸 并传入拉伸的view
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view );
//scrollView是否结束拉伸,并传入拉伸的view和拉伸的形变参数scale
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale;
代理方法
// 是否支持滑动至顶部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
return YES;
}
// 滑动到顶部时调用该方法
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidScrollToTop");
}
// scrollView 已经滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidScroll");
}
// scrollView 开始拖动
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
NSLog(@"scrollViewWillBeginDragging");
}
//检测是否结束拖动,并传入两个参数结束时的速度和偏移量。
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
}
// scrollView 结束拖动,变量decelerate yes表示拖动结束时scrollView带有速度,no表示拖动直接停止。
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"scrollViewDidEndDragging");
}
// scrollView 开始减速
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
NSLog(@"scrollViewWillBeginDecelerating");
}
// scrollview 停止减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidEndDecelerating");
}
eg:如何获取UIScrollView停止滑动
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if ( !decelerate ) {
[self p_scrollViewEndScroll:scrollView];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self p_scrollViewEndScroll:scrollView];
}
- (void)p_scrollViewEndScroll:(UIScrollView *)scrollView {
}