-2

When I press my button, nothing happens. How can I fix this?

And the integer x is declared in the .h file. Edit: the button defines a value for x , and as you see in the code , x is added to the rotation duration. When I press the button , the duration doesn't increase. Here's my code:

#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
Joseph
  • 149
  • 1
  • 2
  • 7
  • 1
    Seeing your code, your button isn't supposed to do anything except set the value of an instance variable you declared. – duci9y Jul 30 '14 at 16:28
  • What do you mean no effect in `viewDidLoad`? Can you give more detail as to what you're expecting? – AdamPro13 Jul 30 '14 at 16:38
  • Thank you for the reply , please check the edit in my question again. My point is , when I press the button , the rotation duration didn't increase. – Joseph Jul 30 '14 at 17:05

1 Answers1

0

viewDidLoad method executes only once in view controller object lifetime. It executes after all the child subviews of it's view has been loaded. You have to declare animation object at class level and then change it's duration in button's ibaction.

praths
  • 353
  • 1
  • 14