0

我正在开发一个应用程序,其中有一个 UITableView,它有一个选择栏,应该突出显示选定的单元格。选择栏是动画的,应该移动到表格内选择的任何单元格。不幸的是,我的图像没有突出显示正确的单元格。相反,它突出显示其上方两行的单元格。我不确定为什么会这样。我已将 UITableView 和 UIImageView 添加到 Interface Builder 的主视图中。下面是我的相关代码:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


    [UIView animateWithDuration:.3 animations:^{
        CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
        _imageView.frame = rect;
    }];

}

谁能看到我做错了什么,以及我需要做些什么来纠正这个问题?

提前感谢所有回复的人。

4

1 回答 1

0

我认为这可能是因为没有从该方法中获得所需的矩形。您的矩形在 tableView 的坐标系中显示框架矩形。尝试将 rect 从表视图的坐标系更改为根视图的坐标系,其中 _imageView 是其子视图。

CGRect rect = [self.view convertRect:[tableView rectForRowAtIndexPath:indexPath] fromView:tableView];
于 2013-06-05T20:36:03.240 回答