我有一堆水平 UITableView 放在 UIViewController1 中。我想找到被点击的 UITableViewCell 的位置,我想根据 UIViewController1 获得位置。所以这是我在 didSelectRowAtIndexPath 中所做的:

MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];

                UIView *animatedView = [[UIView alloc] initWithFrame:cell.frame];
 [animatedView setFrame:[animatedView convertRect:animatedView.frame toView:self.newsRackController.view]];

但是,这似乎没有正确转换它。我究竟做错了什么?

最佳答案

您需要从 UITableView 的 View 转换 UITableViewCell 的 CGRect,然后再次将其转换为您的 View Controller View 。

但除此之外,也许你可以只使用 UITableView 的方法

- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath

获取此 CGRect 并将其转换为您的 UIViewController 的 View 。

关于iphone - convertRect 获取 super View 中的相对位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12272906/

10-11 14:55
查看更多