Je souhaite effectuer une animation sur le thread principal (car les objets UIKit ne sont pas thread-safe), mais le préparer dans un thread séparé. J'ai (baAnimation - est CABasicAnimation attribué & inited avant):Exécution de sélecteurs sur le thread principal avec NSInvocation
SEL animationSelector = @selector(addAnimation:forKey:);
NSString *keyString = @"someViewAnimation";
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[workView.layer methodSignatureForSelector:animationSelector]];
[inv setTarget:workView.layer];
[inv setSelector:animationSelector];
[inv setArgument:baAnimation atIndex:2];
[inv setArgument:keyString atIndex:3];
[inv performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:NO];
je reçois:
***
+ [longueur NSCFString]: sélecteur non reconnu envoyé à la classe 0x1fb36a0
Appels:
> #0 0x020984e6 in objc_exception_throw
> #1 0x01f7e8fb in +[NSObject doesNotRecognizeSelector:]
> #2 0x01f15676 in ___forwarding___
> #3 0x01ef16c2 in __forwarding_prep_0___
> #4 0x01bb3c21 in -[CALayer addAnimation:forKey:]
> #5 0x01ef172d in __invoking___
> #6 0x01ef1618 in -[NSInvocation invoke]
Mais [workView.layer addAnimation:baAnimation forKey:@"someViewAnimation"];
fonctionne très bien. Qu'est-ce que je fais mal?
Cela devrait être la réponse correcte acceptée, car c'est le plus gros problème (ne pas passer le bon truc du tout, par opposition à un problème de gestion de la mémoire) – user102008