Kumar sonu
Kumar sonu

Reputation: 535

How to rotate an image using touch

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.....

Upvotes: 2

Views: 576

Answers (2)

nacho4d
nacho4d

Reputation: 45078

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

Upvotes: 5

Marcelo Cantos
Marcelo Cantos

Reputation: 185852

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.

Upvotes: 3

Related Questions