如何在tableview中获取节头的绝对位置? [英] how to get the absolute position of a section header in tableview?

查看:82
本文介绍了如何在tableview中获取节头的绝对位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在tableview中获取节头的绝对位置?

how to get the absolute position of a section header in tableview?

我已经使用了 tableView:viewForHeaderInSection:获取标题的视图。但现在我需要在屏幕上获取此视图的绝对位置。
返回值的帧不是屏幕中的绝对位置。我也尝试调用superview,但似乎无效。

I have already used the tableView:viewForHeaderInSection: to get the header's view.But now i need to get the absolute position of this view in the screen. the return value's frame is not the absolute position in the screen.I also tried to call superview,but it seems not work.

推荐答案

tableView:viewForHeaderInSection:是一个 UITableViewDelegate 方法,用于创建显示的标题视图。但是,这意味着视图尚未被添加到视图层次结构中,使得它的框架对于您的目的毫无意义。

tableView:viewForHeaderInSection: is a UITableViewDelegate method for creating a header view for display. This means, however, that the view has not been added to the view hierarchy, rendering it's frame meaningless for your purposes.

尝试

UIView *headerView = [tableView headerViewForSection:sectionIndex];

。从那里,您可以在返回的视图上尝试以下方法,以在任何其他视图的坐标系中获取视图的矩形:

instead. From there you can try the following methods on the returned view to get the rect of the view in any other view's coordinate system:

[headerView convertRect:[headerView bounds] toView:[headerView window]];

这篇关于如何在tableview中获取节头的绝对位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆