iphone:从subview获取有关self.view的坐标

时间:2013-01-31 12:31:57

标签: iphone coordinates cgrect

Reference

这里,A,B ... Z是带表格的自定义单元格,

如何针对CGRect的按钮获得self.view?我尝试使用CGRectIntersectionCGRectUnion方法,但它不起作用! 对于例如我需要CGRectself.view

中为我提供该按钮的位置

1 个答案:

答案 0 :(得分:0)

您需要两个计算步骤

  1. 根据 self.view
  2. 计算单元格的来源
  3. 计算相对于单元格的按钮的来源
  4. 对于第1步,您可以使用

    [UITableView rectForRowAtIndexPath]
    

    e.g。 CGRect rect_cell = [table_view rectForRowAtIndexPath:index_path_target_cell];

    然后对于第2步,(如果您还不知道按钮与单元格原点的偏移量)

    CGRect rect_button = _button.frame;
    CGPoint point_answer = CGPointMake(rect_cell.origin.x + rect_button.origin.x , rect_cell.origin.y + rect_button.origin.y);
    
相关问题