代码之家  ›  专栏  ›  技术社区  ›  Slee

获取UITableView中UITextField的帧以显示uipoover

  •  0
  • Slee  · 技术社区  · 14 年前

    我需要在UITableView中呈现来自动态生成的UITextFields的uipoover。它们都是唯一标记的,但当我尝试使用此代码时,弹出窗口只显示在左上角:

    [self.numbersPopover presentPopoverFromRect:[self.childSkusTable viewWithTag:aTag].frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    

    编辑:
    我看到我正在查找该标记项的帧,但它与其父单元格相关,在这种情况下,该标记项的帧对于x,y是0,0。如何在主窗口视图中获取它的位置?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Community CDub    7 年前

    回答这个只是为了满足别人的需要。

    您必须在UIWindow中获得UiTextFields位置,如下所示:

    UIView *v = [self.view viewWithTag:aTag];
    CGPoint pos = [v.superview convertPoint:v.frame.origin toView:nil];
    

    然后我就这么做了:

    [self.numbersPopover presentPopoverFromRect:CGRectMake(pos.x, pos.y, 35, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    

    上面的查找定位代码表单来自以下问答: iPhone - Get Position of UIView within entire UIWindow