开发者

How to rotate an image using touch

开发者 https://www.devze.com 2023-02-05 05:19 出处:网络
Can anyone tell me that how can i rotate a view with respect to touch given by user.... 开发者_运维技巧

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

How to rotate an image using touch

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消