横向TableVIew的实现
方法一:设置tableview属性:
_tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
设置cell属性
cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
方法二:横向UITableView已经有开源实现了 ,EasyTableView,https://github.com/alekseyn/EasyTableView
#import <UIKit/UIKit.h>
@interface BasePictureTableView :UITableView<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSArray *data;
//选中单元格IndexPath
@property(nonatomic,retain)NSIndexPath *selectedIndexPath;
@end
#import "BasePictureTableView.h"
@implementation BasePictureTableView
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
self = [superinitWithFrame:frame style:style];
if (self) {
[self_initViews:frame];
}
return self;
}
- (void)awakeFromNib
{
[superawakeFromNib];
[self_initViews:self.frame];
}
- (void)_initViews:(CGRect)frame
{
//1.逆时针旋转90度
self.transform =CGAffineTransformMakeRotation(-M_PI_2);
//2.旋转之后宽高互换了,所以重新设置frame
self.frame = frame;
self.dataSource =self;
self.delegate =self;
//3.隐藏滚动条
self.showsVerticalScrollIndicator =NO;
//4.设置减速的方式,UIScrollViewDecelerationRateFast快速减速
self.decelerationRate =UIScrollViewDecelerationRateFast;
//5.背景设置为透明
self.backgroundColor = [UIColorclearColor];
//6.隐藏分割线
self.separatorStyle =UITableViewCellSeparatorStyleNone;
}
#pragma mark - override layoutSubViews
#warning mark 第九天修改
- (void)setRowHeight:(CGFloat)rowHeight
{
super.rowHeight = rowHeight;
CGFloat edge = (self.width-self.rowHeight)/2;
//设置滚动的区域
self.contentInset =UIEdgeInsetsMake(edge, 0, edge, 0);
}
#pragma mark - UITableView dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identify =@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
if (cell == nil) {
cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identify] autorelease];
cell.contentView.backgroundColor = [UIColorgrayColor];
//将单元格视图顺时针旋转90度
cell.contentView.transform =CGAffineTransformMakeRotation(M_PI_2);
}
return cell;
}
//- (void)layoutSubviews
//{
// CGFloat edge = (self.width - self.rowHeight)/2;
// self.contentInset = UIEdgeInsetsMake(edge, 0, edge, 0);
// [super layoutSubviews];
//}
//点击单元格调用的协议方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//将单元格滚动到中间
[selfscrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTopanimated:YES];
//记下选中的单元格索引
self.selectedIndexPath = indexPath;
}
//停止拖拽调用,(手指离开滚动视图时调用)
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
//手指离开视图时,滚动视图是禁止状态在调用scrollCellToCenter
if (!decelerate) {
[selfscrollCellToCenter];
}
}
//已经减速停止后调用的协议方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[selfscrollCellToCenter];
}
//将单元格滚动到中间位置
- (void)scrollCellToCenter
{
//计算居中单元格的行索引
// CGFloat edge = (self.width - self.rowHeight)/2;
CGFloat edge =self.contentInset.top;
float y =self.contentOffset.y + edge+self.rowHeight/2;
int row = y / self.rowHeight;
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:row inSection:0];
//滚动到指定单元格
[selfscrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTopanimated:YES];
//记下选中的单元格索引
self.selectedIndexPath = indexPath;
}
@end
横向TableVIew的实现相关推荐
- iOS 常用动画第三方
动画 Core Animation笔记,基本的使用方法 - Core Animation笔记,基本的使用方法:1.基本动画,2.多步动画,3.沿路径的动画,4.时间函数,5.动画组. awesome- ...
- iOS 项目源码大全 github 国内外大神
github排名https://github.com/trending,github搜索:https://github.com/search 主要工作说明: 重新整理了Xcode好用的插件,信息更详细 ...
- iOS开发常用三方库、插件、知名博客
TimLiu-iOS iOS开发常用三方库.插件.知名博客等等,期待大家和我们一起共同维护,同时也期望大家随时能提出宝贵的意见(直接提交Issues即可). 持续更新... 版本:Objective- ...
- iOS最全的三方库、插件、博客汇总
目录 UI@ 日历三方库@ 下拉刷新@ 模糊效果@ 富文本@ 图表@ 颜色@ 表相关@(TabbleView.Tabbar.即时聊天界面) TableView@ CollectionView@ 隐藏与 ...
- iOS开发第三方大全
UI 下拉刷新 EGOTableViewPullRefresh- 最早的下拉刷新控件. SVPullToRefresh- 下拉刷新控件. MJRefresh- 仅需一行代码就可以为UITableVie ...
- iOS 常用第三方库及插件
//菜单切换 https://github.com/pujiaxin33/JXCategoryView //各种导航栏样式 https://github.com/rickytan/RTRootNavi ...
- iOS 开发的资源整理
本文整理了常用的iOS.mac开源项目及类库,是开发者必备的一份资料,现在分享给广大的iOS程序员兄弟们,希望给他们的开发工作带来帮助. UI 下拉刷新 EGOTableViewPullRefresh ...
- iOS开发之资料收集
github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自github:https://github ...
- iOS、mac开源项目及库
1.用来生成 @3x 的图片资源对应的 @2x 和 @1x 版本,只要拖拽高清图到 @3x 的位置上,然后按Ctrl+Shift+A即可自动生成两张低清的补全空位.当然你也可以从 @2x 的图生成 @ ...
最新文章
- cloudera hbase集群简单思路
- pythondocx批量提取目录及内容_一个可以选择目录生成doc目录内容的小工具(三) -python-docx...
- 好婚姻必定是灵魂佳偶
- C#面向对象10 继承
- Nginx 项目部署和配置
- Dubbo透传traceId/logid的一种思路
- 深入了解FileNet
- 学语言python研究生专业目录一览表_本科专业与研究生学科专业目录对照表格模板...
- Java对excel表格操作
- QQ、微信、QQ浏览器UserAgent
- 【黄啊码】微信小程序外卖项目显示骑手位置
- 读取XML-致冷冽同学
- 【无标题】利润与利润提成
- C#下使用第三方开源控件读取Excel文件的内容
- 【IntelliJ IDEA】UTF-8编码下\u7528\u6237转换为中文汉字,\u9489\u9489\u81EA\u5B9A\u4E49\(Unicode字符与中文的相互转化)
- win7多重引导 linux,如何在Linux和Windows下制作多重引导USB?
- ATFX:离岸人民币“破7”,开始还是结束?
- 美团基于跨平台 Flutter 的动态化平台建设
- 树的结点数+蒲丰投针概率
- 橡皮鸭程序调试法[转] 相当有趣^_^