2010-01-03 7 views
2

Comment puis-je me débarrasser de ces avertissementsComment corriger cet avertissement "ne répond pas"?

"Attention: 'UIButton' ne peut pas répondre à '-setPosition:'

et

" Attention: 'UIButton' ne peut pas répondre à « - addAnimation: forKey »

Je les ai ici:

- (void)monBtnIn { 

[monButton setPosition:CGPointMake(113.5,256.5)]; 
[monButton addAnimation:[self monInAnimation] 
        forKey:@"position"]; 

}

Tout construit et se charge bien mais je n'aime pas les avertissements. Je suppose que c'est quelque chose à voir avec le fait que c'est un UIButton et non un CALayer. Alors, comment est-ce que je peux faire cela pour un UIButton?

le fichier .h

IBOutlet UIButton *monButton; 

C'est le KeyFrameAnimation - il crée une animation 'springy' qui installe.

- (CAAnimation*)monInAnimation { 
CGMutablePathRef path = CGPathCreateMutable(); 
CGPathMoveToPoint(path,NULL,113,520); 
CGPathAddLineToPoint(path, NULL, 113.5, 286); 
CGPathAddLineToPoint(path, NULL, 113.5, 242); 
CGPathAddLineToPoint(path, NULL, 113.5, 270); 
CGPathAddLineToPoint(path, NULL, 113.5, 250); 
CGPathAddLineToPoint(path, NULL, 113.5, 262); 
CGPathAddLineToPoint(path, NULL, 113.5, 254); 
CGPathAddLineToPoint(path, NULL, 113.5, 258); 
CGPathAddLineToPoint(path, NULL, 113.5, 256.5); 

CAKeyframeAnimation * 
animation = [CAKeyframeAnimation 
      animationWithKeyPath:@"position"]; 

[animation setPath:path]; 
[animation setDuration:1.5]; 
NSArray *arr = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], 
[NSNumber numberWithFloat:0.12], 
[NSNumber numberWithFloat:0.24], 
[NSNumber numberWithFloat:0.36], 
[NSNumber numberWithFloat:0.48], 
[NSNumber numberWithFloat:0.60], 
[NSNumber numberWithFloat:0.72], 
[NSNumber numberWithFloat:0.84], 
[NSNumber numberWithFloat:1.0],nil]; 

[animation setKeyTimes:arr]; 
[animation setTimingFunctions:[NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
           [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], nil]]; 
//[animation setAutoreverses:YES]; 
CFRelease(path); 
return animation; 

}

Merci beaucoup à l'avance pour vous aider!

Répondre

3

Avez-vous essayé cibler la couche elle-même avec

[monButton.layer setPosition:CGPointMake(113.5,256.5)]; 
[monButton.layer addAnimation:[self monInAnimation] 
        forKey:@"position"]; 
+0

Bien sûr! ... Merci! – Jonathan

2

Je suggère fortement que vous allumez l'option du compilateur « avertissements Objective-C comme des erreurs » dans vos projets iPhone; J'ai écrit un article sur mon blog qui explique comment faire:

http://akosma.com/2009/07/16/objective-c-compiler-warnings/

Cela vous aidera à éviter les problèmes d'exécution comme celui-ci. À mon humble avis, vous ne devriez jamais expédier le code avec des avertissements.

+1

A une excellente métaanswer ... +1 – bbum

+0

Merci ... oui je n'aime pas les avertissements non plus. Je vais lire votre article de blog. Merci – Jonathan

Questions connexes