我在 ViewController 中有一个 TableView,当我选择一个单元格时,我想检查它是否低于某个 y 限制。
y 限制是根据 viewController 的 View 。
我取了单元格的原点并根据 ViewController 的 View 对其进行了转换。
这里我使用了 UIView 类的方法:convertPoint:fromView:
在这里,我将 tableView 本身作为 fromView 参数传递,考虑到它是单元格的直接父 View ,并且单元格的框架将与 tableView 相关。
我看到我得到的新点的 y 值比我应该得到的有所增加。
有没有更好的方法来实现这一目标?
最佳答案
CGRect rectOfCellInTableView = [tableView rectForRowAtIndexPath:indexPath];
CGRect rectOfCellInSuperview = [tableView convertRect:rectOfCellInTableView toView:[tableView superview]];
NSLog(@"cell rect is : %@",NSStringFromCGRect(rectOfCellInSuperview));
关于ios - 如何根据包含 tableview 的 View Controller 转换单元格框架的原点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16962828/