Hello, I'm a beginner in Objective-C and I'm trying to make a clock. I'm just testing at the moment and my problem is that for each loop the needle rotates from its initial position but not from the last position. So, my question is how to make the next rotation in the for
loop from the last position the needle got?
Help me please, i'm doing my last school year internship. Here is my code:
#import "MainView.h"
#include < math.h>
static inline double radians (double degrees) {return degrees * M_PI/180;}
@implementation MainView
int cranTest = 3.1415279;
int tps = 0;
@synthesize aiguille;
@synthesize tempsEcoule;
@synthesize timer;
- (IBAction)go {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkTime) userInfo:nil repeats:YES];
}
-(void)checkTime{
if(tps < 12){
[self updateLabel];
[self tourne];
}else{
[timer invalidate];
tempsEcoule.text = @"terminé";
}
}
-(void)updateLabel{
tps += 1;
tempsEcoule.text = [NSString stringWithFormat:@"%i",tps];
}
-(void)tourne{
CABasicAnimation *spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
spinAnimation.fromValue = 0;
spinAnimation.toValue = [NSNumber numberWithFloat:cranTest];
spinAnimation.duration = .5;
[aiguille.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
}
@end