2011-11-27 80 views
0

所以我有一個一般的圖像旋轉問題。我能夠找到如何進行旋轉並使其正確縮放,但現在我想將其設置爲使圖像在用戶觸摸的位置旋轉。在選擇點旋轉圖像

目前,一旦觸摸,圖像的頂部將旋轉到最初發生觸摸的位置。無論如何,它會保持在圖像上的點,並從那一點開始旋轉?

謝謝你的幫助。

+0

您應該發佈一些您嘗試過的代碼,即使它不起作用。對於想要回答你的問題的人來說,這將是一大幫助! – aganders3

+0

如果您的問題已得到解答,請將解決方案作爲答案發布,並通過單擊答案旁邊的檢查來接受答案。 –

回答

0

修復了我的代碼。只需在ACTION_DOWN被調用時獲得初始度數,然後在ACTION_MOVE期間按照該度數偏移旋轉。 下面的代碼

 //Finds the initial degree where my finger is pressed. 
     case MotionEvent.ACTION_DOWN:{ 
      double arc = Math.atan2(event.getX() - v.getWidth()/2, v.getHeight()/2 - event.getY()); 
      initDegree = (float) Math.toDegrees(arc); 
      setTitle("counter" + counter++); 
      break;} 
     // Using the Initial Degree change I offset the degrees to send to my rotate function. 
     case MotionEvent.ACTION_MOVE:{ 
      double arc = Math.atan2(event.getX() - v.getWidth()/2, v.getHeight()/2 - event.getY()); 
      float degrees = (float) Math.toDegrees(arc); 
      rotate(degrees-initDegree); 
      break;}