0

ビューが他の 2 つのビューの間の中心を維持するだけでなく、自由に移動して、独自の変換を「センタリング」変換に追加したい。たぶん、次のように要約できます: ビューはゼロから始まり、それを中心にする変換が適用されます。次に、ローカル変換が追加されます

説明: 1、2、3 と呼ぶ 3 つのビューがあります。3 つのビューはすべて、パン ジェスチャ レコグナイザーを介して移動できます。

ビュー One が移動すると、Two と Three の両方が、基本的に私のhandlePanメソッドで以下のコードを使用して続きます。

     if (recognizer.view == One){
        Two.center = CGPointMake(Two.center.x + translation.x, Two.center.y + translation.y);
        Three.center = CGPointMake(Three.center.x + translation.x, Three.center.y + translation.y);
     }

handlePanView Three は、私のメソッドで以下のコードを介して One と Two の間の中心を維持します。

    float midX = (One.center.x + Two.center.x)/2;
    float midY = (One.center.y + Two.center.y)/2;  
    Three.center = CGPointMake(midX + translation.x, midY+ translation.y);

これはすべて正常に機能します。問題は、ビュー 3 を「自由に」移動させ、その中心を維持することですが、独自の変換が追加されていることです。私がやりたいことをより簡単に確認できるように、イロを参照してください。

ここに画像の説明を入力

次の設定を試しましたが、うまくいきません。

     if (recognizer.view == One){
        Two.center = CGPointMake(Two.center.x + translation.x, Two.center.y + translation.y);
        Three.center = CGPointMake(Three.center.x + translation.x, Three.center.y + translation.y);
     } else if (recognizer.view == Two)  {
        float midX = (One.center.x + Two.center.x)/2;
        float midY = (One.center.y + Two.center.y)/2;  
        Three.center = CGPointMake(midX + translation.x, midY+ translation.y);
     }

読んでくれてありがとう!

4

1 に答える 1

0

私はそれを解決しました。ものすごく単純。ビュー3とジェスチャレコグナイザによって生成された翻訳を保存するためのポイント(ここでは2つのフロートnumXとnumYを使用)を作成しました。次に、ビュー2を移動するときにそれを適用します。このコードは私のhandlePanメソッドにあります:

 if (recognizer.view == One){
    Two.center = CGPointMake(Two.center.x + translation.x, Two.center.y + translation.y);
    Three.center = CGPointMake(Three.center.x + translation.x, Three.center.y + translation.y);
 } else if (recognizer.view == Two)  {
    float midX = (One.center.x + Two.center.x)/2;
    float midY = (One.center.y + Two.center.y)/2;  
    Three.center = CGPointMake(midX + numX, midY+ numY);
 } else if (recognizer.view == Three) {
    numX = numX+translation.x;
    numY = numY+translation.y;
 }
于 2013-01-25T08:13:13.973 に答える