基本的に、私がやりたいことは、ユーザーのパンに合わせてビューを移動することです。これは、同じパン オブジェクトが使用されている限り正常に機能します。問題は、ユーザーが放してから別のパンを開始したときに発生します。
ドキュメントによると、値translationInView
はパンの開始位置に相対的です。
したがって、これを処理するための私の戦略は、ビューに 2 つのプロパティを追加して、同じパン オブジェクトが使用されているかどうか、および参照位置が何であるかを確認できるようにすることでした。self
オブジェクトは移動中のオブジェクトです。UIView サブクラスです。
CGPoint originalPoint;
if (pan == self.panObject) {
//If the pan object is the same as the one in the property, use the saved value as the reference point.
originalPoint = CGPointMake(self.panStartLocation.x, self.panStartLocation.y);
} else {
//If the pan object is DIFFERENT, set the originalPoint from the existing center.
//self.center is in self.superview's coordinate system.
originalPoint = CGPointMake(self.center.x, self.center.y);
self.panStartLocation = CGPointMake(originalPoint.x, originalPoint.y);
self.panObject = pan;
}
CGPoint translation = [pan translationInView:self.superview];
self.center = CGPointMake(originalPoint.x+translation.x, originalPoint.y+translation.y);
各パン オブジェクトは明らかに同じオブジェクトであるため、このスキームは機能しません。これを確認するためにデバッガーで少し時間を費やしましたが、それは本当のようです。パン オブジェクトはタッチごとに異なると思いました。これはうまくいかないので、代替手段は何ですか?