Iphone 闪烁的颜色
我试图让iPhone的背景颜色每X秒改变一次颜色 我该怎么做Iphone 闪烁的颜色,iphone,objective-c,xcode,colors,Iphone,Objective C,Xcode,Colors,我试图让iPhone的背景颜色每X秒改变一次颜色 我该怎么做 我一直在尝试UIAnimation,但只能将其更改为列表中的最后一种颜色。您可以使用自定义动画单步执行颜色数组,或者只使用计时器。计时器将调用设置所选背景颜色的函数,然后在视图上调用setNeedsDisplay。E.E -(void) timerEntry { UIColor* color = [colorArray objectAtIndex: colorIndex++]; self.backgroundColor = c
我一直在尝试UIAnimation,但只能将其更改为列表中的最后一种颜色。您可以使用自定义动画单步执行颜色数组,或者只使用计时器。计时器将调用设置所选背景颜色的函数,然后在视图上调用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];
您可以使用自定义动画单步执行颜色数组,也可以只使用计时器。计时器将调用设置所选背景颜色的函数,然后在视图上调用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];
如何实现数组和colorIndex?数组是您希望使用的颜色数组,colorIndex表示当前选择。这只是示例代码,您可以让timerEntry函数选择您喜欢的颜色。如何实现数组和colorIndex?数组是您希望使用的颜色数组,colorIndex表示当前选择。这只是示例代码,您可以让timerEntry函数选择您喜欢的颜色。