用tableview来做scrollview

最近在研究scrollview的时候,发现其实tableview同样也能完成我们想要的效果,废话不多说,上代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero];
    tableView.transform = CGAffineTransformMakeRotation(M_PI/-2);
    tableView.frame = CGRectMake(0, 0, 320, 568);
    tableView.rowHeight = 320;
    tableView.bounces = NO;
    tableView.pagingEnabled = YES;
    tableView.showsHorizontalScrollIndicator = NO;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
}


#pragma mark - UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CellIdentifier];
        cell.textLabel.transform = CGAffineTransformMakeRotation(M_PI/2);
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    if (indexPath.row % 2 == 0) {
        cell.backgroundColor = [UIColor redColor];
    }else{
        cell.backgroundColor = [UIColor orangeColor];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    return cell;
}

打完收工。

参考:

[http://code4app.com/ios/%E6%B0%B4%E5%B9%B3tableView/519594ed6803faeb49000000]
这里我发现两个问题
1.例子中scrollview的frame设置了两次,但是第一次会被第二次覆盖,不知道他咋想的?
2.[table.layer setAnchorPoint:CGPointMake(0.0, 0.0)];作者设置了这个属性,自己经过研究才发现这是个锚点的设置,不明白作者这样设置锚点的意义何在?
[http://wonderffee.github.io/blog/2013/10/13/understand-anchorpoint-and-position/]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ¥关闭¥ 【雷霆战机】 〖http://pan.baidu.com/s/1kVstszX〗 《解压源码后直接用AI...
    小菜c阅读 9,847评论 0 19
  • ¥开启¥ 【雷霆战机】 〖http://pan.baidu.com/s/1kVstszX〗 《解压源码后直接用AI...
    小菜c阅读 3,697评论 1 10
  • @synthesize和@dynamic分别有什么作用?@property有两个对应的词,一个是 @synthes...
    笔笔请求阅读 642评论 0 1
  • 文:梦兮夜谈 大冰在他的书中有过这样的描述:“不要那么孤独,请相信,这个世界上真的有人在过着你想要的生活,愿你我带...
    MagicDay阅读 857评论 0 1
  • 这几天没有写简书,因为不知道该写些什么,我又回到了最初的状态,焦虑,不安,不知道该怎么办。孩子因为球队参加比赛...
    雅志清新阅读 292评论 10 3

友情链接更多精彩内容