【问题标题】:UITableViewCell fill color with animationUITableViewCell 用动画填充颜色
【发布时间】:2016-06-25 02:41:58
【问题描述】:

从右端开始,我必须在UITableViewCell 中填充颜色(或者更好地说,在一小段时间内从右到左更改UITableViewCell 的背景)。我怎样才能做到这一点?

【问题讨论】:

    标签: ios uicolor uitableview ios-animations


    【解决方案1】:

    这很容易。

    只需在背景中放置一个视图,从 0 宽度开始,在 tableview/tableview 单元格的右侧,然后将其动画到父视图的整个宽度。

    代码 sn-p(以 Swift 游乐场的形式)

    导入 UIKit 导入 XCPlayground

    let tableView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
    tableView.backgroundColor = UIColor.whiteColor()
    
    var animatedBackroundColorView = UIView(frame: CGRect(x: tableView.frame.width, y: tableView.frame.origin.y, width: tableView.frame.width, height: tableView.frame.height))
    animatedBackroundColorView.backgroundColor = UIColor.orangeColor()
    tableView.addSubview(animatedBackroundColorView)
    UIView.animateWithDuration(1) { () -> Void in
        animatedBackroundColorView.frame = tableView.frame
    }
    XCPShowView("identifier", view: tableView)
    

    转发:

    【讨论】:

    • 我添加了 sn-p :)
    【解决方案2】:

    试试这个

    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width + 1,0,cell.frame.size.width,cell.frame.size.height)];
    [backgroundView setBackgroundColor:yourColor];
    [cell addSubview:backgroundView];
    [UIView animateWithDuration:2.0 animations:^{
         CGRect rect = backgroundView.frame;
         rect.origin.x = 0;
         [backgroundView setFrame:rect];
    } completion:NULL];
    

    【讨论】:

    • 这不是OP要求的(从右到左填充背景颜色)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 2014-06-16
    • 1970-01-01
    相关资源
    最近更新 更多