2

Can anyone tell me that how can i rotate a view with respect to touch given by user....

I mean i want to make similar appearance like the old telephones were(press and rotate to dial...)...alt text

I know very well how to rotate but was unable to rotate according to this situation.....

Kumar sonu
  • 535
  • 11
  • 24
  • I just wrote a long answer about this here: http://stackoverflow.com/questions/1119743/how-to-rotate-image-around-center-point-automatically-with-finger-touch/6910074#6910074 – Markus Knappen Johansson Aug 02 '11 at 09:47

2 Answers2

5

You need a view with only the dial image.

This view has a center C(x,y)
First, the view will be touched at coordinate T0(x,y)

if the x and y is within the circle do the tracking:
    Then the finger will move to coordinate Tn(x,y) 
    Find the angle made up by Tn(x,y) C(x,y) T0(x,y)  //(See below for a reference)
    and do the rotation using that angle as you already know ;)
else
   do nothing since the touch is not in the dial 

Ref: How to calculate an angle from three points

Community
  • 1
  • 1
nacho4d
  • 43,720
  • 45
  • 157
  • 240
3

Calculate angle between the starting touch and the center of the dial (atan2f(y - yc, x - xc)), and use that as the basis angle to determine the rotation required for each subsequent touch event.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365