這是一個不同的問題,但我認爲是錯誤的沒有錯,所以我調整了標題以反映我真正想到的。訪問現有的UITableViewCell
我正在處理一個動畫,它需要在正常的UITableViewCell的cell.imageView中將圖像的副本移動到屏幕底部的選項卡欄上,以模擬將物品放入購物車。我可以複製圖像並將副本作爲窗口的子視圖,但我無法弄清楚如何獲得原始圖像的絕對位置,以便將它放在頂部作爲動畫的起點。
圖像始終顯示在屏幕的頂部,好像置於0,0一樣。
對不起,這個問題沒有問題,我相信我錯過了一些非常明顯的東西。
- (空)的tableView:(UITableView的 *)的tableView accessoryButtonTappedForRowWithIndexPath:(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
}
我想我想通了。當我調用[自我tableView:tableView cellForRotAtIndexPath ....]。我沒有獲得對現有單元格的參考。我從頭開始獲得一個新的「複製」單元。所以當我試圖獲得關於細胞位置的信息時,我實際上已經獲得了我的細胞拷貝的位置,這個位置還沒有正確鋪設。 – Donk 2011-02-25 01:31:14