ios - 在 UITableview 重叠单元格中制作节标题

标签 ios swift uitableview

我试图在我的表格 View 中下推部分标题,使其与部分中的第一个单元格重叠,类似于个人资料图片在左侧 linkedin 应用程序中的显示方式:

linkedin app screenshot

因此,如果白色 View 与个人资料图片重叠是该部分的第一行,个人资料图片是部分标题。

我试过将框架的 x 坐标更改为负值并调整标题的大小,但都无济于事。

最佳答案

我刚刚在 LinkedIn 应用程序中查看个人资料 View ,我想如果我要构建类似的东西,我会把所有个人资料信息放在 tableHeaderView 中。因此 header 将包含以下内容:

  • UIImageView(背景图片)
  • UIView(包含配置文件 信息)
  • UIImageView(用户个人资料图片)

enter image description here

由于 UITableView 是 UIScrollView 的子类,您可以使用委托(delegate)方法 scrollViewDidScroll 为背景图像设置动画。然后,您可以在 tableview 滚动时调整背景图像的位置

@property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 64 is the height of the navigation bar.
    // 110 is the maximum distance I want to move the image down before it starts to move with the table.
    CGFloat offset = MIN(scrollView.contentOffset.y + 64, 110);
    self.backgroundImage.transform = CGAffineTransformMakeTranslation(0, offset);
}

关于ios - 在 UITableview 重叠单元格中制作节标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46228098/

相关文章:

ios - 将 Objective-C block 定义为属性 - 最佳实践

ios - HTTP 请求适用于 curl 但不适用于 iOS 或 Postman

ios - 多点连接广告商进度跟踪

ios - 当 self 被调用时,自定义 CTPlotDataSource 未被调用

ios - 在 Swift 的 UITableView 部分获取行的 [NSIndexPath] 数组

ios - 解除意外行为

objective-c - swift 扩展 "Method definition not found"

ios - Swift 3.0 xCode 8 迁移 pod

Swift 2.2 UITableViewHeaderFooterView 透明

iphone - iOS——在单元格了解其大小后配置 UITableViewCell