5

I would like to show the user's current location while toggling Location mode on Free Ride in the Simulator. It's working fine, but take a look at the image below:

enter image description here

enter image description here

I want this image to rotate as the direction of the route changes. How can I do that? Here you can download the project. I have not implemented route on the below project, I only changed the arrow's direction towards the route.

Cesare
  • 9,139
  • 16
  • 78
  • 130
  • I think you should access to the gyroscope and then adjust the rotation of the image accordingly. – Cesare Jun 28 '15 at 13:16
  • Thanks for the comment..i have been waiting since days....i have no idea about that?? –  Jun 28 '15 at 17:52
  • I have no idea, but 1) Isn't there a framework to integrate Apple's navigator in your app? 2) Try looking on Github, there're plenty of projects like this one. 3) I've edited your question, this might help getting more answers. – Cesare Jun 28 '15 at 18:13
  • thanks a lot...can you provide me some links? –  Jun 29 '15 at 03:40

1 Answers1

3

If I understand your question correctly, you want your arrow to be aligned with the path drawn in the map, at every position on the path.

What I'd do is create a CAKeyframeAnimation with its path property set to the path on the map, and its rotationMode set to kCAAnimationRotateAuto. Add this animation to an image view containing the arrow.

Once you've added the animation, set the imageView.layer.speed = 0 and control imageView.layer.timeOffset to move the arrow. This value goes from 0 to 1, and interpolates it to a position on the path.

CoreAnimation will now automatically rotate the view in a tangential direction to the path at every point.

rounak
  • 9,217
  • 3
  • 42
  • 59
  • yes..you knew that correctly....ok i will give a try..can you just do it in my demo project if you got some free time? –  Jun 29 '15 at 03:41
  • @copeME I'm sorry, I won't be able to do that. I believe I've explained this in a manner that should be easy to implement, however if you encounter a problem, feel free to ask. – rounak Jun 29 '15 at 06:46
  • 1
    @copeME If this worked for you, please mark the answer as correct. Thanks. – rounak Jul 03 '15 at 12:50
  • sadly.. i still dont know how to implement this..i tried but couldnot???if you could help –  Jul 03 '15 at 14:12
  • @copeME where exactly did you get stuck? – rounak Jul 03 '15 at 14:13
  • sorry to say i dont know about CAKeyframeAnimation ...and how to use this..i googled a lot..couldnot get much help...thats why i put a bounty on this question :( –  Jul 03 '15 at 14:14
  • CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.path = path; [view.layer addAnimation:animation forKey:@"position"]; – rounak Jul 03 '15 at 14:20
  • can you explain me how to do this "Add this animation to an image view containing the arrow".? –  Jul 04 '15 at 03:05
  • My previous comment is exactly that. – rounak Jul 04 '15 at 10:31