viewDidLoad中的IBAction没有效果



当我按下按钮时,没有任何反应。我该如何解决这个问题?

整数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

viewDidLoad方法在视图控制器对象生命周期中只执行一次。它在它的视图的所有子视图被加载后执行。你必须在类级别声明动画对象,然后在按钮的ibaction中改变它的持续时间。

最新更新