views:

560

answers:

2

Hi,

How do I get rid of these warnings

"Warning:'UIButton' may not respond to '-setPosition:'

and

"Warning:'UIButton' may not respond to '-addAnimation:forKey'

I get them here:

- (void)monBtnIn {

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

}

Everything builds and loads fine but I dont like warnings. I assume its something to do with the fact that its a UIButton and not a CALayer.

So, how do I make this work for a UIButton?

the .h file

IBOutlet UIButton *monButton;

This is the KeyFrameAnimation - it creates a 'springy' animation that settles.

- (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;

}

Thank you very much in advance for you help!

+2  A: 

Have you tried targeting the layer itself with

[monButton.layer setPosition:CGPointMake(113.5,256.5)];
[monButton.layer addAnimation:[self monInAnimation] 
                    forKey:@"position"];
Niels Castle
Of course!...Thank you!
Jonathan
+2  A: 

I strongly suggest you switch on the "Objective-C warnings as errors" compiler option in your iPhone projects; I've written an article on my blog that explains how to do that:

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

This will help you avoid runtime problems like this one. IMHO you should never ship code with warnings.

Adrian Kosmaczewski
A an excellent metaanswer... +1
bbum
Thanks... yes I don't like warnings either. I will read your blog post. Thanks
Jonathan

related questions