UIView动画不会延迟!

问题描述:

我对自己的线程运行的这样一个简单的UIView的backgroundColor过渡: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];} 

的颜色永远不会随着时间而改变,动画就好像没有任何延迟,而且背景变化如此之快,AppReviewers会根据导致癫痫发作的文章拒绝我的应用程序。请有人帮助我理解为什么动画不会随着时间推移而改为闪光!

+0

欢迎光临。 StackOverflow使用Markdown而不是BBCode。要格式化为源代码,请缩进4个空格或1个选项卡。有关格式指南,请参阅http://stackoverflow.com/editing-help。 – kennytm 2010-02-28 19:22:30

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