01.轮播图之二 :tableView 轮播
在做这个tablevew轮播的时候,重要的就是修改frame 和view 的翻转了::::
也是不难的,概要的设计和scroll 轮播是一致的;
首先是 .h 的文件
@interface TableViewShuffling : UIView @property (nonatomic,strong)NSArray *array; @end
重要的点在.m 文件中加载了详细的注释
@interface TableViewShuffling ()<UITableViewDelegate,UITableViewDataSource> @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,strong)NSMutableArray *tableArray; @end @implementation TableViewShuffling
@synthesize array = _array;
- (instancetype)initWithFrame:(CGRect)frame{ if ( self = [super initWithFrame:frame]) {
}
return self;
} -(UITableView*)tableView{ if (_tableView == nil) {
/*
_tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2); CGRect tabelRect = CGRectMake(10, 10, self.frame.size.height-20, self.frame.size.width-20);
重点:::
因为table view 翻转 90度角 ,所以frame 设计的时候 宽高 ==互 换===了
*/
CGRect tabelRect = CGRectMake(, , self.frame.size.height-, self.frame.size.width-); _tableView = [[UITableView alloc] initWithFrame:tabelRect style:UITableViewStylePlain];
[self addSubview:self.tableView];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.pagingEnabled = YES; // scrollbar 不显示
//tableview逆时针旋转90度。
_tableView.transform = CGAffineTransformMakeRotation(-M_PI / );
/* _tableView.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
重点::: 同样,因为翻转的关系,要把table 重写设置初始位置
*/
_tableView.center = CGPointMake(self.frame.size.width / , self.frame.size.height / );
}
return _tableView;
} -(void)setArray:(NSArray *)array{ NSAssert(array.count != , @"传入的滚动数组是 空的");
_array = array;
[self prepareData];
[self prepareUI];
} -(void)prepareUI{
/*
跳转到 row 1===
*/
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow: inSection:] animated:YES scrollPosition:UITableViewScrollPositionTop];
[self.tableView reloadData];
} - (void)prepareData{ self.tableArray = [NSMutableArray new];
// 首位 添加数组最后的元素
[self.tableArray addObject:_array.lastObject];
// 添加数组元素
[self.tableArray addObjectsFromArray:_array];
// 末尾 补充第一个元素
[self.tableArray addObject:_array.firstObject];
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
/*
row height 千万分清楚 应该是 width 还是haigh 的值
*/
return self.frame.size.width-;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.tableArray.count;
} - (UITableViewCell *)tableView :( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath*)indexPath
{
/*
为什么 不要用系统cell,必须自定义??
因为你设置 这个tableShuffling view 高度小的时候,会影响titlelabel 等属性显示不全,因为翻转的时候,他们的位置没有改变
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
// cell顺时针旋转90度
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
}
cell.textLabel.text = [NSString stringWithFormat:@"';llkjjjjjjhgfds1234567890-=qwertyuioyuiop[asdfghjkl;zxcvbnm,====%ld",(long)indexPath.row];
cell.textLabel.numberOfLines = 0; cell.contentView.backgroundColor = (UIColor*)self.tableArray[indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; */ ShufflingCell *cell = [ShufflingCell getCellForTableView:tableView withIdentifier:@"ShufflingCell" andIndexPath:indexPath];
/*
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
table View 翻转了,但是要把 cell 翻转回正常的状态,否则自定义的cell 显示也是翻转的
*/
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / );
cell.contentView.backgroundColor = (UIColor*)self.tableArray[indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView == self.tableView) { //检测移动的位移
if (scrollView.contentOffset.y == (self.tableArray.count-)*(self.frame.size.width-) ) { [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow: inSection:] animated:NO scrollPosition:UITableViewScrollPositionTop]; }else if (scrollView.contentOffset.y == ){ [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:(self.tableArray.count-) inSection:] animated:NO scrollPosition:UITableViewScrollPositionTop]; }else{ // 正常滚动
} }
}
table view 的滚动视图也基本完成,好久没写了,过程有点曲折;
总结下重点:::
- frame 翻转前后设置
- row Height 的设置
- table 翻转后 cell正常显示,一定要翻转回去
外部调用方法:::::
-(void)prepareTableShuffling{
TableViewShuffling *tableffling = [[TableViewShuffling alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width -, )];
[self.view addSubview:tableffling];;
tableffling.array = self.arr;
}
辛苦的我,今天想早点下班,明天继续……………………
01.轮播图之二 :tableView 轮播的更多相关文章
- 01.轮播图之一 :scrollView 轮播
接触的每个项目,都会用到轮播图的部分,轮播图都写了好多次,用过各种各样的方式写: 这篇总结的博客,我将分为几个篇幅写,希望写完这几篇博客之后,我能总结出自己写这个轮播的优缺和不同之处 scrollvi ...
- js原生选项卡(自动播放无缝滚动轮播图)二
今天分享一下自动播放轮播图,自动播放轮播图是在昨天分享的轮播图的基础上添加了定时器,用定时器控制图片的自动切换,函数中首先封装一个方向的自动播放工能的小函数,这个函数中添加定时器,定时器中可以放向右走 ...
- 仿爱奇艺视频,腾讯视频,搜狐视频首页推荐位轮播图(二)之SuperIndicator源码分析
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼:http://blog.csdn.net/hejjunlin/article/details/52510431 背景:仿爱奇艺视频,腾讯视频 ...
- jQuery轮播图(二)利用构造函数和原型创建对象以实现继承
本文是在我开始学习JavaScript继承时,对原型继承的一些理解和运用.文中所述的继承方式均是使用js特有的原型链方式,实际上有了ES6的类之后,实现继承的就变得十分简单了,所以这种写法现在也不在推 ...
- jquery特效(4)—轮播图②(定时自动轮播)
周末出去逛完街,就回公司好好地研究代码了,也算是把定时自动轮播程序写出来了,特意说明一下,这次的轮播图是在昨天随笔中jquery特效(3)—轮播图①(手动点击轮播)的基础上写出来的,也就是本次随笔展示 ...
- 带轮播图、导航栏、商品的简单html,以及轮播图下边数字随轮播图的改变而改变
---恢复内容开始--- 在做这个的时候,最不会的是中间轮播图下边的数字是如何实现转变的,后来加入了jQuery就能实现了. css部分: <style type="text/css& ...
- jQuery轮播图(一)轮播实现并封装
利用面向对象自己动手写了一个封装好的jquery轮播组件,可满足一般需求,不仅使用简单且复用性高. demo:点此预览 代码地址:https://github.com/zsqosos/componen ...
- JS轮播图(网易云轮播图)
JS 轮播图 写在前面 最聪明的人是最不愿浪费时间的人.--但丁 实现功能 图片自动切换 鼠标移入停止自动播放,显示按钮 点击按钮,实现前后翻 鼠标移入小圆圈,可以跳转到对应图片 点击左右两侧图片部分 ...
- 01.轮播图之三 : collectionView 轮播
个人觉得 collection view 做轮播是最方便的,设置下flowlayout 其他不会有很大的变动,没有什么逻辑的代码 let's begin…… 创建自定义的view .h 声明文件 @i ...
随机推荐
- 遍历器Iterator--指针对象
一. 什么是遍历器 1. 遍历器对象(Iterator) 遍历器对象本质上是一个指针对象,该对象有一个next方法,调用next方法返回一个 含有value和done属性的对象{value: val/ ...
- PostgreSQL 用户、角色、权限管理
PostgreSQL是一个多用户数据库,可以为不同用户指定允许的权限. 角色 PostgreSQL使用角色的概念管理数据库访问权限. 根据角色自身的设置不同,一个角色可以看做是一个数据库用户,或者一组 ...
- PostgreSQL 数据目录结构
根目录介绍 data ├── base # use to store database file(SELECT oid, datname FROM pg_database;) ├── global # ...
- 元素(element)创建
一.元素创建的三种方式-------元素创建是为了提高用户的体验 1.第一种 document.write("标签代码及内容") <input type="butt ...
- 【模板】杜教筛(Sum)
传送门 Description 给定一个正整数\(N(N\le2^{31}-1)\) 求 \[ans1=\sum_{i=1}^n \varphi(i)\] \[ans_2=\sum_{i=1}^n \ ...
- Ubuntu系统下安装完成tomcat进入管理页面
首先先启动tomcat cd /usr/local/tomcat8. ./bin/startup.sh 然后再打开浏览器 在地址栏中输入 http:/localhost:
- vue日常学习
1.$refs可以用来进行父子级间通信.ref被用于作为子组件的索引ID,用以方便的在js中直接访问子组件.用法如下parent.$refs.idname 使用方法: 在父级元素上加上ref属性 &l ...
- kde下面设置plasma_notes字体
只要编辑home目录下vim .local/share/plasma_notes/06af6151-fd00-4cf4-890b-96d783da03,例如: 1 <!DOCTYPE HTML ...
- try 和 catch 的用法
try块是什么? 一个try块就是程序尝试去执行一段代码,try块后面会有几个异常处理块,如果try块中发生了异常,程序执行流就会进入相应的异常处理块中. 以下程序会帮助理解这个概念 #include ...
- 标准6轴机器人正反解(1)-坐标系和MDH参数表
刚来新公司不久,部门给安排了新人作业,我被分到的任务是求标准6轴机器人的正反解,以及利用就近原则选择最优解.从今天开始,逐步将这部分内容总结出来: 本文以及后续文章均使用改进DH法: 连杆坐标系: 坐 ...