【问题标题】:How to retain or animate subview background color in UITableViewCell on selection?如何在选择时在 UITableViewCell 中保留或设置子视图背景颜色?
【发布时间】:2010-11-02 06:54:50
【问题描述】:

我有一个 UIView 作为 UITableViewCell 的自定义子类的子视图。我正在使用它来动态更改单元格的一小部分区域的颜色。

当我选择单元格时,整个单元格的背景色——包括子视图的背景色——都变为蓝色。没关系,它是瞬间发生的。选择向下钻取到另一个视图控制器。

但是,当我从视图控制器返回时,它会将背景再次从蓝色变为白色——但它不会为我的子视图的背景颜色设置动画。效果是蓝色动画到白色,然后突然变回我原来的颜色。

我该怎么做

  • 完全不改变此子视图的背景颜色,
  • 或为过渡设置动画以便我的颜色得到很好的返回?

谢谢!

【问题讨论】:

    标签: iphone cocoa-touch uiview uitableview


    【解决方案1】:

    下面展示了如何为颜色变化设置动画:

    UIView * blue = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 20)];
    [self.view addSubview:blue];
    blue.backgroundColor = [UIColor whiteColor];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    blue.backgroundColor = [UIColor blueColor];
    [UIView commitAnimations];
    [blue release];
    

    希望您可以根据自己的需要进行调整。

    汤姆

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      • 2011-11-18
      相关资源
      最近更新 更多