UITableview 水平滾動

我分析APP,發現居然使用的是UITableview水平滾動,而不是正常認為的UICollectionView.

簡要說明:

1、先將tableview逆時針旋轉90度: self.tableView.transform = CGAffineTransformMakeRotation(-M_PI_2);

2、再將UITableViewCell順時針旋轉90度: cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2);

3、另外需要注意的是

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return tableView.frame.size.width; // 返回的是寬度

}

效果圖:


代碼如下:

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUITableView*tableView;

@property(nonatomic,strong)NSArray*tableDataArray;

@end

@implementationViewController

staticNSString*MyCellID =@"thisIsMyCellId";

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor= [UIColorwhiteColor];

self.tableDataArray=@[[UIColorredColor], [UIColoryellowColor], [UIColorblueColor]];

self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;

self.tableView.scrollsToTop=NO;

self.tableView.transform=CGAffineTransformMakeRotation(-M_PI_2);

self.tableView.showsVerticalScrollIndicator=NO;

self.tableView.pagingEnabled=YES;

self.tableView.bounces=NO;

[self.tableViewregisterClass:[UITableViewCellclass]forCellReuseIdentifier:MyCellID];

_tableView.delegate=self;

_tableView.dataSource=self;

}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

{

returnself.tableDataArray.count;

}

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath

{

returntableView.frame.size.height;

}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

UITableViewCell*cell = [self.tableViewdequeueReusableCellWithIdentifier:MyCellIDforIndexPath:indexPath];

cell.contentView.transform=CGAffineTransformMakeRotation(M_PI_2);

cell.selectionStyle=UITableViewCellSelectionStyleNone;

UIColor*color = [self.tableDataArrayobjectAtIndex: indexPath.row];

[cell.contentViewsetBackgroundColor: color];

returncell;

}

@end

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容