UIScrollView相关参数笔记
@interface ViewController ()<UIScrollViewDelegate>
@property(nonatomic,strong)UIScrollView *scrollView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CGSize size = self.view.bounds.size;
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
_scrollView.backgroundColor = [UIColor redColor];
_scrollView.delegate = self;
// 是否支持滑动最顶端
_scrollView.scrollsToTop = NO;
// 设置内容大小
_scrollView.contentSize = CGSizeMake(size.width*3, size.height-64);
// 是否反弹
_scrollView.bounces = NO;
// 是否分页
_scrollView.pagingEnabled = YES;
// 是否滚动
_scrollView.scrollEnabled = NO;
_scrollView.showsHorizontalScrollIndicator = NO;
// 设置indicator风格
_scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
// 设置内容的边缘和Indicators边缘
_scrollView.contentInset = UIEdgeInsetsMake(0, 50, 50, 0);//全部是0的时候固定位置防止偏移
_scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);
// 提示用户,Indicators flash
[_scrollView flashScrollIndicators];
//隐藏竖滑条
_scrollView.showsVerticalScrollIndicator = FALSE;
//隐藏横滑条
_scrollView.showsHorizontalScrollIndicator = FALSE;
// 是否同时运动,lock
_scrollView.directionalLockEnabled = YES;
[self.view addSubview:_scrollView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, size.width, 40)];
label.backgroundColor = [UIColor yellowColor];
label.text = @"第1页";
[_scrollView addSubview:label];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake( size.width, 100, size.width, 40)];
label1.backgroundColor = [UIColor blueColor];
label1.text = @"第2页";
[_scrollView addSubview:label1];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake( size.width*2, 100, size.width, 40)];
label2.backgroundColor = [UIColor whiteColor];
label2.text = @"第3页";
[_scrollView addSubview:label2];
}
滑动相关代理方法
// 视图已经放大或缩小
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
NSLog(@"scrollViewDidScrollToTop");
}
// 是否支持滑动至顶部
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
return YES;
}
// 滑动到顶部时调用该方法
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
NSLog(@"滑动到顶部时调用该方法");
}
// scrollView 已经滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"已经滑动");
}
// scrollView 开始拖动
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
NSLog(@"开始拖动");
}
// scrollView 结束拖动
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"结束拖动");
}
// scrollView 开始减速(以下两个方法注意与以上两个方法加以区别)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"开始减速");
}
// scrollview 减速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"减速停止");
}
放大缩小视图相关代理方法
//返回一个放大或者缩小的视图
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
}
//开始放大或者缩小
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:
(UIView *)view
{
}
//缩放结束时
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
}