2011-10-07 76 views
0

我使用錯誤的類型嗎? CGFloat的?浮動? int,都給我同樣的問題。將對象傳遞給CGFloat類型的方法

我需要我的方法wiggleImage的幫助。我正在嘗試設置一種方法,我可以將對象傳入並使用一種方法調用許多不同的視圖並重新使用代碼。但是,當我在方法內部對anchorPointX和anchorPointY值進行硬編碼時,它工作正常。當我使用過的值,它確實有些奇怪的轉換,正如你可以從日誌輸出看到,它改變了值,比我想過去其他的東西。

- (void)viewDidLoad { 

[self wiggleImage:candleFlickerView 
       duration:.45 
       curve:UIViewAnimationCurveEaseInOut 
       x:10.0 
       y:10.0 
       rotation:1 
       anchorPointX:0.2 
       anchorPointY:0.2]; 
     NSLog(@"VDL AnimationViewController....\n "); 
    } 



- (IBAction)wiggleImage:(UIImageView *)image duration:(NSTimeInterval)duration 
       curve:(int)curve x:(CGFloat)x y:(CGFloat)y rotation:(CGFloat)rotation 
      anchorPointX:(CGFloat)anchorPointX anchorPointY:(CGFloat)anchorPointY 
{ 
// UN HIDE THE VIEW 
image.hidden = FALSE; 

// Setup the animation 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:duration]; 
[UIView setAnimationCurve:curve]; 
[UIView setAnimationRepeatCount:FLT_MAX]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationRepeatAutoreverses:YES]; 
//image.layer.anchorPoint= CGPointMake(0.5,0); 
image.layer.anchorPoint= CGPointMake(anchorPointX, anchorPointY); 


// The transform matrix 
CGAffineTransform transform = CGAffineTransformMakeRotation(-0.45); 
image.transform = transform; 
// Commit the changes 
[UIView commitAnimations]; 
NSLog(@"VDL showing wiggleImage Animation with Values of....\n "); 
NSLog(@"\nX=[%f]", anchorPointX); 
NSLog(@"\nY=[%f]", anchorPointY); 
NSLog(@"\nRotation=[%f]", rotation); 

} 


console output. 
2011-10-07 10:21:54.580 Skippy[16932:c803] VDL showing wiggleImage Animation Values.... 

2011-10-07 10:21:54.581 Skippy[16932:c803] 
X=[2.562500] 
2011-10-07 10:21:54.582 Skippy[16932:c803] 
Y=[0.000000] 
2011-10-07 10:21:54.582 Skippy[16932:c803] 
Rotation=[0.000000] 
2011-10-07 10:21:54.583 Skippy[16932:c803] VDL AnimationViewController.... 
+0

神聖的參數嘔吐!這不是C++。爲什麼wiggleImage是IBOutlet?這不應該只是好奇而已。 此外,您的控制檯日誌消息與我在代碼中看到的內容不匹配,它們是否準確?你的日誌應該正確地輸出這些值,只有很小的問題是你的輪換可能被看作是一個整數,所以可能會有一些轉換。 – EricLeaf

+0

試過你的代碼,它適合我。它正確地打印浮游物。 – Perception

回答

0

wiggleImage宣佈之前,它是用於viewDidLoad?確保它存在於你的類的頭文件中,並且頭文件包含在實現文件中。