日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

01.轮播图之二 :tableView 轮播

發布時間:2025/5/22 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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(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逆時針旋轉90度。_tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2); /*

_tableView.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
重點::: 同樣,因為翻轉的關系,要把table 重寫設置初始位置
*/_tableView.center
= CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);}return _tableView; }-(void)setArray:(NSArray *)array{NSAssert(array.count != 0, @"傳入的滾動數組是 空的");_array = array;[self prepareData];[self prepareUI]; }-(void)prepareUI{
/*
跳轉到 row 1===
*/[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:
1 inSection:0] 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-20; }-(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 / 2);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-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{// 正常滾動 }} }

?

table view 的滾動視圖也基本完成,好久沒寫了,過程有點曲折;

總結下重點:::

  • frame 翻轉前后設置
  • row Height 的設置
  • table 翻轉后 cell正常顯示,一定要翻轉回去
  • 外部調用方法:::::

    -(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; }

    ?

    辛苦的我,今天想早點下班,明天繼續……………………

    轉載于:https://www.cnblogs.com/Bob-blogs/p/6769875.html

    總結

    以上是生活随笔為你收集整理的01.轮播图之二 :tableView 轮播的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。