2011-10-07 85 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?确保它存在于你的类的头文件中,并且头文件包含在实现文件中。