Je simple UIView backgroundColor transition en cours d'exécution sur son propre fil en tant que tel:UIView Animation ne retardera pas!
cependant- (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;
}
}
... quand il court après l'initialisation avec une telle:
colorStatus = colorBegin;
static BOOL colorThread = NO;if(!colorThread) {colorThread = YES;[NSThread detachNewThreadSelector:@selector(colorLoop_thread) toTarget:self withObject:nil];}
les couleurs ne changent jamais au fil du temps, l'animation se déroule comme s'il n'y avait pas de retard du tout et l'arrière-plan change si rapidement que les AppReviewers rejetteraient mon application sous les articles responsables des crises d'épilepsie. S'il vous plaît, aidez-moi à comprendre pourquoi l'animation ne se réalise jamais avec le temps et finit le flash!
Bienvenue. StackOverflow utilise Markdown au lieu de BBCode. Pour mettre en forme comme code source, indentez 4 espaces ou 1 tab. Voir http://stackoverflow.com/editing-help pour le guide de format. – kennytm