0

我正在设置 UIButton 以垂直方向落在 iPad 屏幕上设置代码类似于

CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
theAnimation.repeatCount=1e100;
theAnimation.autoreverses=NO;
for (UIButton *vbtn in flakesArray) {
    //vbtn.userInteractionEnabled =YES;
    [vbtn addTarget:self 
             action:@selector(aMethodTesting:)
   forControlEvents:UIControlEventTouchUpInside];
    CGPoint p = vbtn.center;
     startypos = p.y;
    NSLog(@"%f",startypos);
     endypos = self.view.frame.size.height;
    p.y = endypos;
    NSLog(@"%f",endypos);
    vbtn.center = p;
    //float timeInterval = ((Float32)(animationDurationMax-animationDurationMin)*(Float32)random()/(Float32)RAND_MAX);
    theAnimation.duration=200;
    theAnimation.fromValue=[NSNumber numberWithFloat:-startypos];
    [vbtn.layer addAnimation:theAnimation forKey:@"transform.translation.y"];
    [self.view addSubview:vbtn];
    [self.view bringSubviewToFront:vbtn]; 
}

但是这段代码不允许我的 UIButton 调用方法 aMethodTesting:有什么帮助吗?

4

2 回答 2

0
  1. 您的 aMethodTesting 是否真的将发件人作为参数?如果没有,请删除:
  2. 它应该是 UIButton *vbtn (它是一个指针)

请将您的代码格式化为代码,它现在非常不可读。

于 2012-09-22T17:33:22.883 回答
0

这可能会对您有所帮助,这是对您的代码的编辑。这是单按钮。您可以将其用于多个。

CABasicAnimation *theAnimation = [CABasicAnimation    animationWithKeyPath:@"transform.translation.y"];

theAnimation.repeatCount=1e100;
theAnimation.autoreverses=NO;
float startypos = 1.0f;
float endypos=480.0f;
float animationDurationMax = 500.0f;
float animationDurationMin = 50.0f;
UIButton *vbtn = (UIButton *)sender;
//for ( UIButton *vbtn in flakesArray)
{
    vbtn.userInteractionEnabled =YES;
    [vbtn addTarget:self action:@selector(aMethodTesting:) forControlEvents:UIControlEventTouchUpInside];
    CGPoint p = vbtn.center;
    startypos = p.y;
    NSLog(@"%f",startypos);
    endypos = self.view.frame.size.height;
    p.y = endypos;
    NSLog(@"%f",endypos);
    vbtn.center = p;
    float timeInterval = (animationDurationMax-animationDurationMin);//random()/RAND_MAX);
    theAnimation.duration=2;
    theAnimation.fromValue=[NSNumber numberWithFloat:-startypos];
    [vbtn.layer addAnimation:theAnimation forKey:@"transform.translation.y"];
    [self.view addSubview:vbtn];
    [self.view bringSubviewToFront:vbtn];
}
于 2012-09-29T13:59:42.203 回答