如何在tableview中获取节标题的绝对位置?
如何在tableview中获取节标题的绝对位置?
我已经使用tableView:viewForHeaderInSection:
获取标题的视图。但是现在我需要在屏幕上获得这个视图的绝对位置。 返回值的框架不是在屏幕上的绝对位置。我也试图调用superview,但它似乎不工作。
tableView:viewForHeaderInSection:
是一个UITableViewDelegate
方法,用于创build一个用于显示的标题视图。 然而,这意味着视图还没有被添加到视图层次结构中,从而使得视图对于您的目的而言毫无意义。
尝试
UIView *headerView = [tableView headerViewForSection:sectionIndex];
代替。 从那里你可以在返回的视图上尝试以下方法,以获取其他视图坐标系中的视图的矩形:
[headerView convertRect:[headerView bounds] toView:[headerView window]];
假设您的顶层视图直接包含表视图,该视图又包含标题:
- (CGRect) getHeaderAbsoluteFrame : (UIView *)headerview :(UIView *)tableview { CGRect frame = headerview.frame; CGRect tableFrame = tableview.frame; float x = tableview. origin.x + headerview.frame.origin.x; float y = tableview.frame.origin.y + headerview.frame.origin.y; CGRect rect = CGRectMake (x,y,headerview.frame.size.width, headerview.frame.size.height); return rect; }
- 如何使数组中的每个string成为自己的UITableViewCell,每个string都在自己的部分中?
- 如何在两个ViewController之间传递数据,其中第一个VC有两个tableViews,第二个tableViewselect的数据应该传递给第二个VC?
- 出现键盘时偏移UITableView内容
- 如何在iOS中单击UIButton时将项目插入UITableView
- iOS CustomTableViewCell:元素不能正确alignment
- 如何在UITableView静态单元格中dynamic更改单元格高度
- 当tableview滚动时计数值被改变
- UITableViewController以编程方式访问静态单元格
- 在UITAbleView中缓慢加载来自URL的图像。