Problem with rotating clock needle
صفحه اصلي

Problem with rotating clock needle



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 

should we need to release viewcontroller's object after pushing into navigation controller?

1:

scrollview scrolls smooth in simulator but not in device?
Your code uses a timer to start a CAAnimation every second. Can we run Java applictions on iPhone? [closed]You should rather use the repeatCount property of CAAnimation (from the CAMediaTiming protocol) to enable continuous animation.. What's a Java alternative to Google App Engine for developing iPhone Push Notification services? Using the cumulative or additive properties, you must set up your animation to start the next loop from where the last stopped.. Running JavaScript in a UIWebView before any other JavaScript is run
UIScrollView image/photo viewer with paging enabled and zoomingCreating the Iphone MapKit showUserLocation Ring Annimation

2:

Upload and download data from server with Cocoa Touch?
CABasicAnimation (documentation here) is a subclass of CAPropertyAnimation (documentation here). CAPropertyAnimation has cumulative, and additive.

3:

I'm not sure, don't have experience with CoreAnimation, although I believe you have to set the byValue property:.
Defines the value the receiver uses to perform relative interpolation..
So try:.
spinAnimation.byValue = M_PI/6; 
I'm not sure if you have to did an explicit cast to a float since the property is an id, I'm new to Objective-C as well. So I guess you would have to do:.
spinAnimation.byValue = (float)(M_PI/6); // not sure if this is needed or correct 
I'm not sure you need the cummulative and additive properties set, try commenting them out:.
// spinAnimation.cumulative = YES; // spinAnimation.additive = YES; 
And like David said as a comment to your original post, you will want to set cranTest to be a float instead of an integer, otherwise the value receive s truncated to 3:.
float cranTest = 3.1415279f; 

4:

Try doing this instead:.
spinAnimation.byValue = [NSNumber withFloat:(M_PI/6)]; 
I believe this shouldn't commit any problems. And remember to make the another changes I told you around , like changing cranTest from being an int to being a float.. Also when you reply, don't add an answer, instead, add a comment to the answer. Uh.. répondre à ma réponse avec un comment, pas une autre reponse..


74 out of 100 based on 39 user ratings 434 reviews

*