Skip to content

Commit

Permalink
Merge pull request #1 from QDFish/master
Browse files Browse the repository at this point in the history
改善指南针的流畅度
  • Loading branch information
kiichi committed Jan 8, 2016
2 parents 9c8be54 + 05f4aac commit c3a6b59
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions CompassExample/OGViewController.m
Expand Up @@ -23,15 +23,21 @@ - (void)viewDidLoad{
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
// Convert Degree to Radian and move the needle
float oldRad = -manager.heading.trueHeading * M_PI / 180.0f;
float newRad = -newHeading.trueHeading * M_PI / 180.0f;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
theAnimation.toValue=[NSNumber numberWithFloat:newRad];
theAnimation.duration = 0.5f;
[compassImage.layer addAnimation:theAnimation forKey:@"animateMyRotation"];
compassImage.transform = CGAffineTransformMakeRotation(newRad);
NSLog(@"%f (%f) => %f (%f)", manager.heading.trueHeading, oldRad, newHeading.trueHeading, newRad);
float newRad = -newHeading.trueHeading * M_PI / 180.0f;

[UIView animateWithDuration:0.2
animations:^{
compassImage.transform = CGAffineTransformMakeRotation(newRad);
}];
// CABasicAnimation *theAnimation;
// theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
// theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
// theAnimation.toValue=[NSNumber numberWithFloat:newRad];
// theAnimation.duration = 0.01f;
//
// [compassImage.layer addAnimation:theAnimation forKey:@"animateMyRotation"];
// compassImage.transform = CGAffineTransformMakeRotation(newRad);
NSLog(@"%f (%f) => %f (%f)", manager.heading.trueHeading, oldRad, newHeading.trueHeading, newRad);
}

@end

0 comments on commit c3a6b59

Please sign in to comment.