码迷,mamicode.com
首页 > 其他好文 > 详细

UIScrollView及相关协议方法

时间:2015-09-13 15:54:38      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

//初始化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(@"结束减速 完成");
}

 

UIScrollView及相关协议方法

标签:

原文地址:http://www.cnblogs.com/kyuubee/p/4805017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!