【发布时间】:2011-02-24 22:56:19
【问题描述】:
这是一个不同的问题,但我认为错误并没有错,所以我调整了标题以反映我真正想到的内容。
我正在制作一个动画,该动画在普通 UITableViewCell 的 cell.imageView 中获取图像副本并将其移动到屏幕底部的标签栏,以模拟将商品放入购物车。我可以复制图像并将副本放置为窗口的子视图,但我不知道如何获取原始图像的绝对位置,因此我可以将其放在顶部作为动画的起点。
图像始终显示在屏幕顶部,就像放置在 0,0 处一样。
对不起,这个问题的性质很愚蠢,我确定我遗漏了一些非常明显的东西。
-(void)tableView:(UITableView *)tableView 附件ButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; UIImageView *originalImgView = cell.imageView; UIImageView *img = [[[UIImageView alloc] initWithImage: cell.imageView.image] autorelease]; NSLog(@"Original %@", originalImgView.bounds); // Shows "Original (null)" at runtime. NSLog(@"Window Points %@", [self.view.window convertPoint:originalImgView.frame.origin toView:nil]); NSLog(@"Cell Points: %@", cell.bounds); // Shows "Original (null)" at runtime. [img setFrame:CGRectMake( originalImgView.bounds.origin.x, originalImgView.bounds.origin.y , cell.imageView.image.size.width, cell.imageView.image.size.height)]; [self.view.window addSubview:img]; NSLog(@"Selected Cell: %@", cell); // Shows cell info at run time, works}
【问题讨论】:
-
我想我知道怎么了。当我调用 [self tableView:tableView cellForRotAtIndexPath ....] 时。我没有得到对现有单元格的引用。我正在从头开始获取单元格的新“副本”。因此,当我尝试获取有关单元格位置的信息时,实际上是在获取未正确布局的单元格副本的位置。
标签: ios animation uiview uitableview coordinates