0

私はiPhoneの開発が初めてで、UIButtonをアニメーション化するためにフォリングコードを使用していますが、完全にアニメーション化されていますが、ボタンをクリックするとアクションが起動しません。これから私を助けてください。

 [UIButton animateWithDuration:3.0
                          delay:0.0f
                        options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState
                     animations: ^(void){
                         CGPoint p = Mybutton.center;
                         p.y += 100;
                         Mybutton.center = p;

                     }
                     completion:NULL];
4

1 に答える 1

2

このコードはボタン アクションまたは viewDidLoad にありますか? これを試してください:

   - (IBAction)buttonAnimation:(id)sender {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.duration = .3;
animation.repeatCount = 5;
animation.fromValue = [NSValue valueWithCGPoint:yourButton.center];
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(yourButton.center.x, yourButton.center.y-30)];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
animation.autoreverses = YES;
animation.removedOnCompletion = NO;
[yourButton.layer addAnimation:animation forKey:@"position"];}

ボタンアクションに配置する必要があります。それが役に立てば幸い

于 2013-10-17T14:10:29.867 に答える