J'essaye d'animer un bouton qui se déplace autour de l'écran. À tout moment, l'utilisateur peut appuyer sur le bouton. Mais le bouton ne répond pas aux touches. J'ai essayé un bloc d'animation, mais le bouton se déplace simplement immédiatement à ses coordonnées de fin, alors que le cadre montre l'animation (le bouton est appelé bulle):Est-il possible de réussir à animer un UIButton en mouvement?
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
CGAffineTransform newTransform = CGAffineTransformMakeScale(3, 3);
bubble.transform = CGAffineTransformTranslate(newTransform, 0, -460);
[UIView commitAnimations];
Alors j'ai essayé Core Animation avec l'aide de quelques-uns exemple de code (le chemin est pas important, il est juste un exemple):
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint(thePath,NULL,
15.f,250.0f,
295.0f,250.0f,
295.0f,15.0f);
CAKeyframeAnimation *theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
theAnimation.path=thePath;
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.animations=[NSArray arrayWithObject:theAnimation];
theGroup.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theGroup.duration=15.0;
CFRelease(thePath);
[bubble.layer addAnimation:theGroup forKey:@"animatePosition"];
Mais les boutons ne répond toujours pas aux touches. Btw, j'ai plusieurs de ces boutons 'bulle' sur l'écran à la fois alors avoir plusieurs NSTimers simultanément actifs ne serait pas optimal.
Quelqu'un peut-il suggérer une autre approche? Dois-je peut-être animer UIImageViews et les rendre repsond à toucher? Ou aurai-je le même problème? Cela m'a énervé pendant quelques jours, donc toute aide très appréciée.
Merci :)
Michael
Ouais, j'essaie vraiment de simuler beaucoup de bulles flottantes que le joueur peut faire sauter, je vais essayer cette approche - merci! – Smikey