闪烁的颜色

时间:2009-02-22 19:08:31

标签: iphone objective-c xcode colors

我试图让iPhone背景颜色每隔X秒改变颜色。

我该怎么做?

我一直在尝试使用UIAnimation,但只能将其更改为列表中的最后一种颜色。

1 个答案:

答案 0 :(得分:3)

您可以使用自定义动画来逐步浏览颜色数组,或者只使用计时器。计时器将调用一个函数来设置所选的背景颜色,然后在视图上调用setNeedsDisplay。 E.E。

-(void) timerEntry
{
  UIColor* color = [colorArray objectAtIndex: colorIndex++];
  self.backgroundColor = color;
  [self setNeedsDisplay];
  if (colorIndex == [colorArray count])
    colorIndex = 0;
}

然后设置计时器:

[NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(timerEntry) userInfo: nil repeats: NO];
相关问题