01.轮播图之二 :tableView 轮播
生活随笔
收集整理的這篇文章主要介紹了
01.轮播图之二 :tableView 轮播
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?在做這個(gè)tablevew輪播的時(shí)候,重要的就是修改frame 和view 的翻轉(zhuǎn)了::::
?也是不難的,概要的設(shè)計(jì)和scroll 輪播是一致的;
首先是 .h 的文件
@interface TableViewShuffling : UIView@property (nonatomic,strong)NSArray *array;@end?
重要的點(diǎn)在.m 文件中加載了詳細(xì)的注釋
@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); 重點(diǎn):::
因?yàn)閠able view 翻轉(zhuǎn) 90度角 ,所以frame 設(shè)計(jì)的時(shí)候 寬高 ==互 換===了
*/CGRect tabelRect = CGRectMake(10, 10, self.frame.size.height-20, self.frame.size.width-20);_tableView = [[UITableView alloc] initWithFrame:tabelRect style:UITableViewStylePlain];[self addSubview:self.tableView];_tableView.delegate = self;_tableView.dataSource = self;_tableView.pagingEnabled = YES; // scrollbar 不顯示//tableview逆時(shí)針旋轉(zhuǎn)90度。_tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2); /*
_tableView.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2); 重點(diǎn)::: 同樣,因?yàn)榉D(zhuǎn)的關(guān)系,要把table 重寫設(shè)置初始位置
*/_tableView.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);}return _tableView; }-(void)setArray:(NSArray *)array{NSAssert(array.count != 0, @"傳入的滾動(dòng)數(shù)組是 空的");_array = array;[self prepareData];[self prepareUI]; }-(void)prepareUI{
/*
跳轉(zhuǎn)到 row 1===
*/[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];[self.tableView reloadData]; }- (void)prepareData{self.tableArray = [NSMutableArray new];// 首位 添加數(shù)組最后的元素 [self.tableArray addObject:_array.lastObject];// 添加數(shù)組元素 [self.tableArray addObjectsFromArray:_array];// 末尾 補(bǔ)充第一個(gè)元素 [self.tableArray addObject:_array.firstObject]; }-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ /*
row height 千萬(wàn)分清楚 應(yīng)該是 width 還是haigh 的值
*/return self.frame.size.width-20; }-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return self.tableArray.count; }- (UITableViewCell *)tableView :( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath*)indexPath {/*
為什么 不要用系統(tǒng)cell,必須自定義??
因?yàn)槟阍O(shè)置 這個(gè)tableShuffling view 高度小的時(shí)候,會(huì)影響titlelabel 等屬性顯示不全,因?yàn)榉D(zhuǎn)的時(shí)候,他們的位置沒(méi)有改變
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];if (cell == nil) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];// cell順時(shí)針旋轉(zhuǎn)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 翻轉(zhuǎn)了,但是要把 cell 翻轉(zhuǎn)回正常的狀態(tài),否則自定義的cell 顯示也是翻轉(zhuǎn)的
*/cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);cell.contentView.backgroundColor = (UIColor*)self.tableArray[indexPath.row];cell.selectionStyle = UITableViewCellSelectionStyleNone;return cell;}-(void)scrollViewDidScroll:(UIScrollView *)scrollView{if (scrollView == self.tableView) {//檢測(cè)移動(dòng)的位移if (scrollView.contentOffset.y == (self.tableArray.count-1)*(self.frame.size.width-20) ) {[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];}else if (scrollView.contentOffset.y == 0){[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:(self.tableArray.count-2) inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];}else{// 正常滾動(dòng) }} }
?
table view 的滾動(dòng)視圖也基本完成,好久沒(méi)寫了,過(guò)程有點(diǎn)曲折;
總結(jié)下重點(diǎn):::
外部調(diào)用方法:::::
-(void)prepareTableShuffling{TableViewShuffling *tableffling = [[TableViewShuffling alloc]initWithFrame:CGRectMake(10, 150, self.view.frame.size.width -20, 150)];[self.view addSubview:tableffling];;tableffling.array = self.arr; }?
辛苦的我,今天想早點(diǎn)下班,明天繼續(xù)……………………
轉(zhuǎn)載于:https://www.cnblogs.com/Bob-blogs/p/6769875.html
總結(jié)
以上是生活随笔為你收集整理的01.轮播图之二 :tableView 轮播的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: android 蓝牙低耗能(LBE)技术
- 下一篇: 日志文件清理代码