将对象传递给CGFloat类型的方法

时间:2011-10-07 15:28:00

标签: iphone objective-c xcode sdk core-animation

我使用的是错误的类型吗? CGFloat的?浮动? int,都给我同样的问题。

我的方法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....

1 个答案:

答案 0 :(得分:0)

wiggleImage中使用viewDidLoad之前是否已声明?确保它出现在您的类的标题中,并且标题包含在实现文件中。