//初始化scrollview
UIScrollView *scroll =[[UIScrollView alloc]initWithFrame:CGRectMake(0,2 0, 320, 200)];
//用for循环,向scroll中添加图片
//用for循环去创建UIImageView 5
for (int i=0; i<5; i++)
{
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(i*320, 0, 320, 200)];
//拼接图片名字
NSString *nameStr =[NSString stringWithFormat:@"image%d.jpg",i+1];
imageView.image =[UIImage imageNamed:nameStr];
[scroll addSubview:imageView];
}
//设置scrollView的滑动范围
scroll.contentSize =CGSizeMake(320*5, 0);
//设置scrollView的分页
scroll.pagingEnabled =YES;
//设置scrollView横竖向的显示条是否显示 Horizontal横
scroll.showsHorizontalScrollIndicator =NO;
//Vertical 竖
scroll.showsVerticalScrollIndicator =YES;
//设置当前scrollView的偏移量
//设置x.y向负方向的偏移量
scroll.contentOffset =CGPointMake(0, 0);
//设置代理
scroll.delegate =self;
[self.view addSubview:scroll];
//开始拖曳
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
//Dragging 拖拽
NSLog(@"开始拖拽");
}
//结束拖曳
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"结束拖拽");
}
//开始减速
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
NSLog(@"开始减速");
}
//结束减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"结束减速 完成");
}