最近经常使用 UIScrolloView 简单的总结了一下经常使用的方法
只写一下 滚动的 方法和属性吧
UIScrollView *scro = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
scro.frame = CGRectMake(0, 0, self.view.frame.size.width + 10, self.view.frame.size.height);
scro.backgroundColor = [UIColor greenColor];
// scrollview 多与循环搭配使用
for (int i = 0; i < 3; i++) {
UIImageView *im = [[UIImageView alloc] initWithFrame:CGRectMake(i * (self.view.frame.size.width + 10), 0, self.view.frame.size.width, self.view.frame.size.height)];
NSString *a = [NSString stringWithFormat:图片名称];
im.image = [UIImage imageNamed:a];
[scro addSubview:im];
}
// 设置最大偏移量
scro.contentSize = CGSizeMake(self.view.frame.size.width * 3 + 30, 0);
// 设置整页便宜(默认值为NO)
// 整页偏移是以scrollo的 宽度 为 一页 计算的 而非 屏幕宽度
scro.pagingEnabled = YES;
// scrollView滚动的位置
[self.view addSubview:scro];
[scro release];
// 起始位置
scro.contentOffset = CGPointMake(scro.frame.size.width, 0);
// 点击状态栏返回顶部
scro.scrollsToTop = YES;
// 边缘的弹动效果
scro.bounces = NO;
// 隐藏滚动条
scro.showsHorizontalScrollIndicator = NO;
// 设置代理人
scro.delegate = self;
#pragma mark - 滚动
//当scrollView 发生偏移的时候响应
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"偏移%f",scrollView.contentOffset.x);
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
NSLog(@"开始拖拽");
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"结束拖拽");
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
NSLog(@"开始减速");
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"减速结束");
}
-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
NSLog(@"回滚到顶部");
}