ios - 如何获取 uibutton(UITableViewCell 的 subview )相对于整个窗口 iOS objective-C 的位置?

标签 ios objective-c iphone uitableview coordinates

如问题所述,我想获得图像中显示的 uibutton 的位置,并且我必须显示该 uibutton 的弹出菜单(在 tableviews View 中)。

我经历了Question1Question2 .但是这些给了我不同的位置。

我用代码

    CGRect windowRect = [_tableView convertRect:button.frame fromView:tempCell];

临时单元格是我选择的单元格。

我正在使用 kxMenu 作为弹出菜单,我使用以下代码。

[KxMenu showMenuInView:_tableView
              fromRect:windowRect
             menuItems:menuItems];

所以,我需要正确获取 windowRect。有人知道吗?

enter image description here

enter image description here

最佳答案

如果你使用

 [_tableView convertRect:button.frame fromView:tempCell];

它会将按钮的帧 wrt tempcell 转换为按钮帧 wrt _tableView

如果你想在窗口中获取按钮的框架,你应该做任何一个

 [button convertRect:button.bounds toView:nil];

 [button.superView convertRect:button.frame toView:nil];

关于ios - 如何获取 uibutton(UITableViewCell 的 subview )相对于整个窗口 iOS objective-C 的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33914943/

相关文章:

iphone - 旋转设备时发生反向卷页

iphone - 我怎样才能只舍入 UIView 的底角?

ios - View Controller 上缺少导航栏

ios - 如何以编程方式在 UIView 的中心添加文本?

ios - CLLocationManager 初始更新不太准确

ios - 如何在 UITableView 中禁用排序

iphone - 找不到 Cocos2D CGRectIntersect?

ios - 使用 xcodebuild 创建 watchOS2 模拟器构建

objective-c - 使用两个不同的 baseUrl - AFHTTPSessionManager

iphone - NSDateFormatter返回null