Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 闪烁的颜色_Iphone_Objective C_Xcode_Colors - Fatal编程技术网

Iphone 闪烁的颜色

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

我试图让iPhone的背景颜色每X秒改变一次颜色

我该怎么做


我一直在尝试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函数选择您喜欢的颜色。