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 ...
随机推荐
- Luogu P4198 楼房重建 (李超线段树)
题目 传送门 题解 首先转化成到(0,0)(0,0)(0,0)的斜率. 那么就是求多少个点是前缀最大值. 做法是线段树,用gao(i,x)gao(i,x)gao(i,x)表示在iii区间内,之前最大值 ...
- Python pip 虚拟环境使用
安装: pip install virtualenv 使用,创建虚拟环境: cd project_dir virtualenv venv #venv为虚拟环境 目录名自定义 virtualenv -p ...
- JavaScript是如何工作的02:深入V8引擎&编写优化代码的5个技巧
概述 JavaScript引擎是执行 JavaScript 代码的程序或解释器.JavaScript引擎可以实现为标准解释器,或者以某种形式将JavaScript编译为字节码的即时编译器. 以为实现J ...
- HTML 005 段落
HTML 段落 HTML 可以将文档分割为若干段落. HTML 段落 段落是通过 <p> 标签定义的. 实例 <p>这是一个段落 </p> <p>这是另 ...
- linux系列(八):cp命令
1.命令格式: cp [选项]... [-T] 源 目的 2.命令功能: 将源文件复制至目标文件,或将多个源文件复制至目标目录. 3.命令参数: -a:此参数的效果和同时指定"-dpR&qu ...
- 3、Web server 之httpd2.2 配置说明
http协议实现的程序 静态(httpd, nginx, lighttpd) 动态 (IIS, tomcat, jetty, jboss, resin, websphere, weblogic ...
- lucene正向索引(续)——域(Field)的元数据信息在.fnm里,在倒排表里,利用跳跃表,有利于大大提高搜索速度。
4.1.2. 域(Field)的元数据信息(.fnm) 一个段(Segment)包含多个域,每个域都有一些元数据信息,保存在.fnm文件中,.fnm文件的格式如下: FNMVersion 是fnm文件 ...
- 知乎面试【五轮技术+HR】
今年下半年去知乎面试了两次,讲道理来说,知乎有CD期, 一旦上一次面试没有通过.在一段时间内,不能再次面试知乎.后来在同事的内推下,再次获得面试机会,哈哈~~,这次面试时间还是挺长的,特记录一下. 7 ...
- Cross-Site Request Forgery (CSRF)
https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF) Overview Cross-Site Request Forger ...
- 阿里巴巴微服务与配置中心技术实践之道 原创: 坤宇 InfoQ 2018-02-08
阿里巴巴微服务与配置中心技术实践之道 原创: 坤宇 InfoQ 2018-02-08