KVI*_*ISH 15 objective-c uitableview
我有一个UITableView我能够相当容易地添加标题视图.许多应用程序(如Facebook,用于查看事件)都有一个headerView,当你下拉时,标题视图保持不变,但表的其余部分(UITableViewCells)正在反弹.向上滚动标题消失.我该如何实现此功能?
现在当我拉下来时UITableView,即使是headerView也会反弹
omz*_*omz 35
您可以通过向标题视图添加子视图并调整其frame或transform在表格视图滚动到顶部之外(即其y组件contentOffset变为负数)时非常轻松地实现此效果.
示例(在UITableViewController子类中):
- (void)viewDidLoad
{
    [super viewDidLoad];
    CGFloat headerHeight = 64.0f;
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, headerHeight)];
    UIView *headerContentView = [[UIView alloc] initWithFrame:headerView.bounds];
    headerContentView.backgroundColor = [UIColor greenColor];
    headerContentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [headerView addSubview:headerContentView];
    self.tableView.tableHeaderView = headerView;
}
//Note: UITableView is a subclass of UIScrollView, so we
//      can use UIScrollViewDelegate methods.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    UIView *headerContentView = self.tableView.tableHeaderView.subviews[0];
    headerContentView.transform = CGAffineTransformMakeTranslation(0, MIN(offsetY, 0));
}
(为了简单起见,我刚刚使用了实际标题视图的第一个子视图scrollViewDidScroll:,你可能想要使用一个属性.)
| 归档时间: | 
 | 
| 查看次数: | 10293 次 | 
| 最近记录: |