【发布时间】:2015-01-26 06:23:37
【问题描述】:
我在静态 UITableViewCell 中有一个按钮。我想要做的是在按钮位置放置一个 UIView。
如果我只是得到按钮的位置,它会给我一个相对于 tableviews 单元格的位置,而不是从 tableViewController 的顶部。我想要的是从 tableViewController 的顶部获取按钮位置。
例如:如果按钮距离当前顶部 8px 单元格,但距离 viewController 的顶部 57px,我想 将 UIView 放置在 57px。
这是我的代码:
- (void)viewDidLoad {
CGPoint buttonPosition = [button convertPoint:CGPointZero fromView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
CGRect rect = [myTableView rectForRowAtIndexPath:indexPath];
NSLog(@"%f, %f", rect.origin.y, rect.origin.x);
self.infoView = [[UIView alloc] initWithFrame:CGRectMake(button.frame.origin.x, button.frame.origin.y, 220, 110)];
}
nslog 的输出为 0。
我还想在 iphone 进入横向模式时更新 UIView 的位置。
【问题讨论】:
-
这是自定义单元格?
-
你有按钮实例吗?
-
按钮从按钮数组中调用,如下所示: UIButton *button = [self.allButtons objecAtIndex:1];
-
在您的 Y 位置添加将行前的行数乘以按钮和行高的结果。但我怀疑有更好的方法来做你想做的任何事情。那么告诉我们,你的真正目标是什么?
-
button.frame.origin.x和button.frame.origin.y为您提供按钮位置
标签: ios objective-c uitableview cgrect