これを行う組み込みのトランジションはありません(ビュー自体とは異なるレートでframe
/をトランジションしている画像について話していると思います)。center
おそらく自分で書く必要があります。ジェスチャ レコグナイザーとビュー アニメーションに関する基本的な知識が必要です。
基本的な効果は、2 つのイメージビュー (またはそれらのスーパー ビュー)center
を変更するときに、2 つのイメージ ビューのプロパティを同時に調整することです。frame
(または、 のイメージ ビューを使用して を変更することで、これを実現できますcontentMode
。UIViewContentModeCenter
)frame
エフェクトの簡単なテストから始めて、そこからビルドすることをお勧めします。
たとえば、オートレイアウトの制約が次のように定義された 2 つのイメージ ビューを持つシーンを作成しました。
H:|[左画像ビュー][右画像ビュー]|
V:|[左画像ビュー]|
V:|[rightImageView]|
次に、 の幅の制約を定義し、その制約leftImageView
の に接続しました。次に、ジェスチャを処理できる があり、それに応じてこれを変更するだけです (自動レイアウトを使用すると、フレームの残りの部分がそこから自動的に計算されます)。IBOutlet
leftImageWidthConstraint
UIPanGestureRecognizer
leftImageWidthConstraint
- (void)handlePan:(UIPanGestureRecognizer *)gesture
{
CGPoint translate = [gesture translationInView:gesture.view];
static CGFloat width;
if (gesture.state == UIGestureRecognizerStateBegan)
{
width = self.leftImageWidthConstraint.constant;
}
CGFloat newWidth = width + translate.x;
if (newWidth < 0)
newWidth = 0;
else if (newWidth > self.view.bounds.size.width)
newWidth = self.view.bounds.size.width;
self.leftImageWidthConstraint.constant = newWidth;
// if you let go, animate the views to their final position
if (gesture.state == UIGestureRecognizerStateEnded)
{
// if more than half way, set left view's target width to take up full width,
// otherwise set left view's target width to zero
if (newWidth > (self.view.bounds.size.width / 2.0))
newWidth = self.view.bounds.size.width;
else
newWidth = 0;
// animate the changing of the constraint (and thus the `frame`) accordingly
self.leftImageWidthConstraint.constant = newWidth;
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
[self.view layoutIfNeeded];
} completion:nil];
}
}
したがって、パンすると、2 つの画像はクリップされたフレーム内の中央に配置されます。

これは、アイデアの非常に基本的な実装です。ただし、実装の詳細 (カスタム コンテナーとサブビュー、自動レイアウトとそうでないものなど) は山ほどあるため、これらの質問のいくつかに答えるまで、より具体的に説明するのは難しいでしょう。