iOS无线滚动系列,轮播图、滚动消息
来源:互联网 发布:1991莫斯科摇滚知乎 编辑:程序博客网 时间:2024/06/14 20:07
类似轮播图,实现无限循环。循环的是一个view,上面放什么东西都可以,比如滚动的消息之类的东西,上面有图片有为类的。
思想:在最后面一个后面拼接第一个,然后判断滚动式图偏移量已经最大的时候,证明是最后面那个第一个,然后是关键了
将滚动式图的偏移量移动到
[_scrollViewsetContentOffset:CGPointMake(0,0) animated:NO];
注意 animated设为NO,悄悄的移到最开始的位置,不要动画,你可以设为YES试试,滚动会闪
紧接着
[_scrollViewsetContentOffset:CGPointMake(0,_scrollView.frame.size.height)animated:YES];
这个时候 animated 是YES,看起来就像是从第一个,滚动到第二个。for (int i = 0; i < (self.modelList.count > 1 ? self.modelList.count + 1 : self.modelList.count); i++) { CGFloat height = self.scrollView.frame.size.height; CGFloat width = self.scrollView.frame.size.width; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, height * i, width, height); button.tag = TagParam + i; [self.scrollView addSubview:button]; [button addTarget:self action:@selector(checkMessageDetail:) forControlEvents:UIControlEventTouchUpInside]; UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 15, 45, 45)]; imageView.backgroundColor = BackGround_Color; [button addSubview:imageView]; UILabel *titleLabel = [UILabel labelShortWithColor:Color_666666 font:17]; [button addSubview:titleLabel]; [titleLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(imageView.right).offset(20); make.top.equalTo(button.top).offset(20); make.right.equalTo(button.right).offset(-20); }]; UILabel *contentLabel = [UILabel labelShortWithColor:Color_999999 font:12]; [button addSubview:contentLabel]; [contentLabel makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(titleLabel); make.bottom.equalTo(button.bottom).offset(-20); }]; VHomeSystemMessageModel *model ; if (i == self.modelList.count) { model = [self.modelList firstObject]; imageView.image = vImage(@""); titleLabel.text = model.title; contentLabel.text = model.content; }else { model = self.modelList[i];; imageView.image = vImage(@""); titleLabel.text = model.title; contentLabel.text = model.content; } } _timer = [NSTimer timerWithTimeInterval:2 target:self selector:@selector(doCycleScroll) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes]; //当数组里面的数据大于1的时候,才会滚动 if (self.modelList.count > 1) { [_timer fire]; } _scrollView.contentOffset = CGPointMake(0, 0);
//上下滚动-(void)doCycleScroll{ CGFloat offsety = _scrollView.contentOffset.y; offsety += _scrollView.frame.size.height; if (offsety > _scrollView.contentSize.height) { [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO]; [_scrollView setContentOffset:CGPointMake(0, _scrollView.frame.size.height) animated:YES]; }else{ [_scrollView setContentOffset:CGPointMake(0, offsety) animated:YES]; }}
0 0
- iOS无线滚动系列,轮播图、滚动消息
- iOS 无线滚动相册之scrollView
- 无线滚动瀑布流
- IOS系列——scrollview自动滚动
- iOS开发系列课程(09) --- 滚动视图
- 【iOS开发系列】tableView滚动淡出效果
- iOS 图片 无线滚动效果 利用 3张UIImageView 实现
- MessageScrollor消息滚动条
- 滚动条消息总结
- ViewPager实现无线循环滚动
- cocos2d js 地图无线滚动
- 无线循环的可自动滚动播放轮播图
- 滚动
- 滚动
- 滚动
- 滚动
- IOS开发系列之UIScrollView(滚动视图)的常用属性和应用举例(滑动相册、轮播图)
- IOS系列——Scrollview的循环滚动
- TextUtils.isEmpty(useName)
- 【Java】 初始化与清理
- Golang--Goroutines
- bzoj 2179 FFT快速傅立叶
- linux系统安装jdk
- iOS无线滚动系列,轮播图、滚动消息
- Tensorflow lesson 2---唯一的结构tensor
- position:ablosute和position:relative的简单理解
- ICNet读书笔记
- erlang 导入库脚本【转】
- Java工程师学习路线
- PCL中的KDtree
- 重温矩阵(IV) 矩阵与函数
- Jenkins进阶系列之——03parameterized-trigger插件