Objective c 为UITableViewCell设置动画';图像视图插入?
嘿,伙计们,(相对而言,我相信)这里有一个简单的问题 我有一个带有UITableView的UITableViewController,其单元格数已确定。如果用户点击单元格,图像将插入相应单元格的imageView属性,如下所示:Objective c 为UITableViewCell设置动画';图像视图插入?,objective-c,cocoa-touch,animation,uitableview,uiimageview,Objective C,Cocoa Touch,Animation,Uitableview,Uiimageview,嘿,伙计们,(相对而言,我相信)这里有一个简单的问题 我有一个带有UITableView的UITableViewController,其单元格数已确定。如果用户点击单元格,图像将插入相应单元格的imageView属性,如下所示: [self.tableView cellForRowAtIndexPath:chosenPersonIndexPath].imageView.image = [UIImage imageNamed:@"tick.jpeg"]; (其中,chosenPersonInde
[self.tableView cellForRowAtIndexPath:chosenPersonIndexPath].imageView.image = [UIImage imageNamed:@"tick.jpeg"];
(其中,chosenPersonIndexPath
只是所选单元格的索引路径)
有没有办法让这个动画化?按原样,UITableViewController只是停留在图像中,没有任何过渡。我所要问的是,是否有一种方法可以使其动画化,如果有,如何实现
非常感谢!
~Joaquim鉴于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文档中“核心动画编程指南”中的“动画属性”一章
希望这有帮助 太棒了!这正是我想要的。非常感谢您耐心地回答16岁新手dev的“新手”问题:D 2010年快乐!