IOS tableview:拉伸图像直到滚动完成才显示

时间:2013-09-03 11:04:55

标签: iphone ios objective-c uitableview

我想在我的项目中创建一个聊天气泡视图。而我把图像拉伸成泡沫。 但问题发生了,如果我将单元格滚动到不可见,则在单元格返回原始位置后,可以拉伸图像,这是显示拉伸图像的唯一方法。

以下图片是有关问题的简要说明。

故事板中的气泡视图布局,UIImageView是拉伸图像:

enter image description here

滚动前: enter image description here

滚动后: enter image description here

最初显示气泡视图时(其原始显示方法:导航栏项目Segue),并在viewWillAppear()中调用拉伸功能,它显示拉伸正常。

以下是关键代码: 细胞中的初始气泡伸展:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
   NSString *cellID = @"chatCell";
    UIBubbleTableViewCell *cell = (UIBubbleTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
   //CAll stretch function
   cell.dataInternal = dataInternal;
}

拉伸功能:

bubbleImage.image = [[UIImage imageNamed:@"chat2.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:14];
bubbleImage.frame = CGRectMake(40, 10, 267, 105);

每次更新时调用拉伸功能:

- (void)viewDidAppear:(BOOL)animated{
[chatTable reloadData];

}

无论如何,只有滚动结束,图像才能显示拉伸。我调试项目,并记录拉伸拉伸数据,一切都很好。

如果有任何建议,我怎么能解决这个问题。

1 个答案:

答案 0 :(得分:3)

您要做的是将图像拉伸功能放在

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

委托方法。只有在这一点上,您才能知道要显示的表格单元格的实际大小。然后你可以将气泡图像拉伸到心脏的内容。