ビューが他の 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);
}
handlePan
View 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);
}
読んでくれてありがとう!