【问题标题】:Animate UITableViewCell's imageView insertion?动画 UITableViewCell 的 imageView 插入?
【发布时间】:2011-01-01 02:15:34
【问题描述】:

大家好,(相对而言,我相信)这里的问题很简单,

我有一个 UITableViewController 和它的 UITableView,它的单元格数量是确定的。如果用户点击某个单元格,则会将图像插入到相应单元格的 imageView 属性中,如下所示:

[self.tableView cellForRowAtIndexPath:chosenPersonIndexPath].imageView.image = [UIImage imageNamed:@"tick.jpeg"];

(其中chosenPersonIndexPath 只是选定单元格的索引路径)

有什么方法可以制作动画吗?照原样,UITableViewController 只是简单地粘在图像中,没有任何过渡。我只想问是否有办法制作动画,如果有,怎么做?

提前非常感谢! ~华金

【问题讨论】:

    标签: objective-c cocoa-touch animation uitableview uiimageview


    【解决方案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 文档中“核心动画编程指南”中的“动画属性”章节以获取更多信息。

    希望这会有所帮助!

    【讨论】:

    • 太棒了!这正是我一直在寻找的。非常感谢您耐心回答一个 16 岁的新手开发者的“新手”问题。 :D 2010 年快乐!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多