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 ...
随机推荐
- 多任务3(协程)--yield完成多任务交替执行
协程是并发,单线程,一次执行一个 来回切换 代码: import time def task_1(): while True: print("-----1-----") time. ...
- feign.RetryableException: Read timed out executing xxx
feign.RetryableException: Read timed out executing GET http://common-item/service/item/selectTbItemA ...
- 008_硬件基础电路_RC消火花电路分析方法和思路
如上图所示是一种RC消火花电路.电路中,+V是直流工作电压,S1是电源开关,M是直流电机,R1和C1构成RC消火花电路. 1.电路分析需要了解火花产生的原因直流电机的内部是一个线圈结构,根据线圈的有关 ...
- 验证账号密码是否为空 if格式
当前台页面是否提示有没有输入账号密码时 这时需要验证 //验证账号是否为空 if(string.IsNullOrEmpty(zh)) { //为空 则提示输入账号 ObjToJsin.msg = &q ...
- oracle 备份恢复之recover database的四条语句区别
1 recover database using backup controlfile2 recover database until cancel3 recover database usin ...
- VS下字符串与数组互相装换
1.分割字符串IdStr为int数组Ids int[] Ids = Array.ConvertAll<string, int>(IdStr.Trim().Split(','), deleg ...
- [Luogu] 运输问题 -- 00
https://www.luogu.org/problemnew/show/4015 #include <bits/stdc++.h> #define gc getchar() using ...
- gulp4配置多页面项目编译打包
又开始公司的新项目了... 那当我们拿到公司新项目的时候我们需要做些什么呢? 下面就来分享一下我的工作步骤吧(仅使用于初学者,大神勿见怪- -,有不好的地方希望指出,十分感谢) 1. 整版浏览 这是一 ...
- 函数第二部分:为什么说动态参数是没有计划好的参数-Python基础前传(11)
动态参数1-一个星号变元组 动态参数存在的意义? 函数的作者有时候也不知道这个函数到底需要多少个参数,这时候动态参数就有存在的意义了 动态参数创建-加* 底层原理是:把数值型或其他数据类型变成了元组类 ...
- windows下java环境变量标准配置
配置步骤 1.“此电脑”右键,选择“属性”,点击“高级系统设置”,点击“环境变量”. 2.在“系统变量”这一栏,点击“新建”,变量名:JAVA_HOME,变量值:C:\Program Files\Ja ...