2010-01-03 72 views
2

如何擺脫這些警告如何解決這個「可能不會迴應」的警告?

的 「警告: '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; 

}

非常感謝你提前爲您的幫助!

回答

3

你有沒有試着用

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

當然!...謝謝! – Jonathan 2010-01-03 11:24:11

2

我強烈建議您開啓「Objective-C的警告視爲錯誤」,在你的iPhone項目的編譯器選項針對層本身;我已經寫在我的博客,解釋如何做到這一點的文章:

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

這將幫助你避免這樣的一個運行時的問題。恕我直言,你永遠不應該將代碼發送警告。

+1

一個優秀的metaanswer ... +1 – bbum 2010-01-03 18:53:47

+0

謝謝...是的,我也不喜歡警告。我會閱讀你的博客文章。謝謝 – Jonathan 2010-01-04 09:59:04