这是一个不同的问题,但我认为错误并没有错,所以我调整了标题以反映我真正想到的.
我正在制作一个动画,它在普通UITableViewCell的cell.imageView中获取一个图像的副本,并将其移动到屏幕底部的标签栏,以模拟将项目放入购物车.我可以复制图像并将副本作为窗口的子视图放置,但我无法弄清楚如何获得原始图像的绝对位置,因此我可以将它放在顶部作为动画的起点.
图像始终显示在屏幕顶部,就像放在0,0一样.
对不起这个问题的noobish性质,我敢肯定我错过了一些非常明显的东西.
- (void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath {
Run Code Online (Sandbox Code Playgroud)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}