Animation UIView动画不会延迟!

Animation UIView动画不会延迟!,animation,uiview,colors,delay,Animation,Uiview,Colors,Delay,我在自己的线程上运行了一个简单的UIView背景色转换,如下所示: - (void)colorLoop_thread { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // [self performSelector:@selector(changeColors)]; [self performSelectorOnMainThread:@selector(changeColors) withObject:nil wa

我在自己的线程上运行了一个简单的UIView背景色转换,如下所示:

- (void)colorLoop_thread {  
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// [self performSelector:@selector(changeColors)];
[self performSelectorOnMainThread:@selector(changeColors) withObject:nil waitUntilDone:NO];

 [pool release];
}

- (void)changeColors {
 if(self.colorStatus == colorBegin) {
  self.backgroundColor = [self randomColor];
  self.colorStatus = colorChanged;
 }

 if(self.colorStatus == colorChanged) {
  self.colorStatus = colorChanging;
  [UIView beginAnimations:@"ChangeColor" context:nil];
  [UIView setAnimationDuration:2.0f];
  [UIView setAnimationDelegate:self];
  [UIView setAnimationDidStopSelector:@selector(changeColorFinished:finished:context:)];
  self.backgroundColor = [self randomColor];
  [UIView commitAnimations];
 }
 [NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(changeColors) userInfo:nil repeats:NO];
}

- (void)changeColorFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
 if([animationID isEqualToString:@"ChangeColor"]) {
  self.colorStatus = colorChanged;
 }
}
然而。。。当它在初始化后运行时,请执行以下操作:

colorStatus = colorBegin;
static BOOL colorThread = NO;if(!colorThread) {colorThread = YES;[NSThread detachNewThreadSelector:@selector(colorLoop_thread) toTarget:self withObject:nil];}

颜色永远不会随时间而改变,动画的运行就像没有任何延迟一样,背景变化如此之快,以至于ApproveViewer会拒绝我在《癫痫发作相关文章》中的应用程序。请有人帮助我理解为什么动画从来没有随着时间的推移而进行,而是闪光完成

试试self.layer.backgroundColor=[[self randomColor]CGColor]。

试试self.layer.backgroundColor=[[self randomColor]CGColor]。

欢迎。StackOverflow使用降价而不是BBCode。要格式化为源代码,请缩进4个空格或1个制表符。有关格式指南,请参见。欢迎。StackOverflow使用降价而不是BBCode。要格式化为源代码,请缩进4个空格或1个制表符。有关格式指南,请参见。