//容量大小
scroll.contentSize = CGSizeMake(0, 0);
//内容区域的偏移量
scroll.contentOffset = CGPointMake(0, 0);
//滚动条的显示样式
scroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
//是否显示滚动条
scroll.showsHorizontalScrollIndicator = NO;//横向滚动条 NO代表不显示
scroll.showsVerticalScrollIndicator = YES;//纵向滚动条
//是否可以滚动
scroll.scrollEnabled = NO;//默认YES(支持滚动)
//是否支持整页滑动
scroll.pagingEnabled = YES;
//方向锁 设置滑动时只能单方向滑动
scroll.directionalLockEnabled = NO;
//反弹效果
scroll.bounces = YES;
//当显示的内容区域小于scroll的边界时依然有回弹效果
scroll.alwaysBounceHorizontal = YES;//始终有水平方向回弹
scroll.alwaysBounceVertical = NO;//始终有垂直方向回弹
//点击状态条 是否偏移到最顶端
scroll.scrollsToTop = YES;
//设置代理 监测scrollView的滚动过程
scroll.delegate = self;
//缩放的比例
scroll.minimumZoomScale = 0.5;
scroll.maximumZoomScale = 2.5;
#pragma mark - UIScrollViewDelegate -
//触发时机: scroll发生滚动时
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//获取偏移量
//NSLog(@"%@", NSStringFromCGPoint(scrollView.contentOffset));
}
//触发时机: scroll上缩放的视图发生缩放时
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2){
//NSLog(@"%s %d", __FUNCTION__, __LINE__);
}
//触发时机: scroll将要开始拖拽时
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
}
//触发时机: scroll将要结束拖拽时
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0){
}
//触发时机: scroll已经结束拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
}
//触发时机: scroll将要减速时
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
}
//触发时机: scroll已经结束减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//当scroll停止滑动时 偏移量置为(0, 0)
//scrollView.contentOffset = CGPointMake(0, 0);//无动画效果
//[scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; //带动画效果
//根据scroll的偏移量计算 index(索引值下标)
NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
}
//触发时机: scroll已经结束滚动
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
}
//设置scrollView上缩放的视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
UIImageView *view = (UIImageView *)[self.view viewWithTag:102];
return view;
}
//触发时机: scroll将要开始缩放时
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2){
}
//触发时机: scroll结束缩放时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
//缩放结束时 还原到原来的大小
//[scrollView setZoomScale:1.0];
[scrollView setZoomScale:1.0 animated:YES];
}
//scroll是否支持点击状态条 偏移到最上端
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
return YES;
}
//scroll已经偏移到最上端时触发(前提是设置scrollView属性为YES) 可做一些刷新的操作
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
}
UIScrollView(滑动视图)
最新推荐文章于 2024-06-28 16:22:49 发布