嘿伙计们,(相对而言,我相信)这里的简单问题,
我有一个UITableViewController及其UITableView,具有确定的单元格数。如果用户点击一个单元格,则会将图像插入到相应单元格的imageView属性中,如下所示:
[self.tableView cellForRowAtIndexPath:chosenPersonIndexPath].imageView.image = [UIImage imageNamed:@"tick.jpeg"];
(其中chosenPersonIndexPath
只是所选单元格的索引路径)
有没有办法动画这个?原样,UITableViewController只是简单地粘贴在图像中,没有任何过渡。我要问的是,是否有可能为此设置动画的方法,如果有,怎么做?
非常感谢提前! 〜若阿金
答案 0 :(得分:1)
鉴于UIImageView实例是UIView实例,您可以像其他任何UIView一样为它们设置动画:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.imageView.alpha = 0.0;
cell.imageView.image = [UIImage imageNamed:@"tick.jpg"];
cell.textLabel.text = @"tap!";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[self.tableView cellForRowAtIndexPath:indexPath].imageView.alpha = 1.0;
[UIView commitAnimations];
}
tableView:didSelectRowAtIndexPath:方法中的动画可以包括翻转,大小更改或任何其他类型的(可动画的)属性更改。有关详细信息,请查看iPhone SDK文档中“核心动画编程指南”中的“可动画属性”一章。
希望这有帮助!