如何修复此“可能无法响应”警告?

时间:2010-01-03 10:31:44

标签: iphone objective-c compiler-warnings warnings

如何摆脱这些警告

“警告:'UIButton'可能无法响应'-setPosition:'

“警告:'UIButton'可能无法响应'-addAnimation:forKey'

我把它们送到这里:

- (void)monBtnIn {

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

}

一切都建立并加载好但我不喜欢警告。我认为它与UIButton而不是CALayer这一事实有关。

那么,我如何为UIButton做这项工作?

.h文件

IBOutlet UIButton *monButton;

这是KeyFrameAnimation - 它会创建一个“有弹性”的动画。

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

}

非常感谢您的帮助!

2 个答案:

答案 0 :(得分:3)

您是否尝试使用

定位图层
[monButton.layer setPosition:CGPointMake(113.5,256.5)];
[monButton.layer addAnimation:[self monInAnimation] 
                    forKey:@"position"];

答案 1 :(得分:2)

我强烈建议您在iPhone项目中打开“Objective-C warnings as errors”编译器选项;我在我的博客上写了一篇文章,解释了如何做到这一点:

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

这将帮助您避免像这样的运行时问题。恕我直言,你不应该发出带警告的代码。