当我按下按钮时,没有任何反应。我该如何解决这个问题?
整数x在.h文件中声明。 编辑:按钮定义x的值,正如您在代码中看到的那样,x被添加到旋转持续时间。当我按下按钮时,持续时间不会增加。 这是我的代码:
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)button1:(UIButton *)sender {x=10;}
- (IBAction)button2:(UIButton *)sender {x=3;
}
- (void)viewDidLoad
{ CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 10+x;
fullRotation.repeatCount= 1000;
[[_stick layer] addAnimation:fullRotation forKey:@"60"];
[super viewDidLoad];
}
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
viewDidLoad方法在视图控制器对象生存期中仅执行一次。它在加载了它的视图的所有子视图后执行。 你必须在类级别声明动画对象,然后在按钮的ibaction中更改它的持续时间。