0

imageView を 1 つセットアップし、UIViewその imageView に を追加しました。は透過的です。今、動的にUIViewさらに追加ImageViewsしています。UIView

動的に追加する ImageView に Pan および Pinch Zoom ジェスチャ レコグナイザをセットアップしたいのですが、ジェスチャ レコグナイザの動作範囲を制限する方法がわかりません。

パン ジェスチャを使用してドラッグされた画像は、その範囲内にとどまるUIView必要があり、その境界線の外にドラッグしてはなりませんUIView

UIViewのは画面の半分しかカバーしていません。

どうすればこれを達成できるかについてのアイデアはありますか?

4

1 に答える 1

2

パンジェスチャメソッドで条件を作成する必要があります

 CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:your view];

if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
    firstX = [your image center].x;//firstX and FirstY is CGFLoat...
    firstY = [your image center].y;

}

if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateEnded)
{
 }
translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);

    if(translatedPoint.x < 0 || translatedPoint.x > 320)
    {
          set your image frame
    }
    else if(translatedPoint.y < 0 || translatedPoint.y > 480)
    {
        set your image frame

    }

     //   [your image setCenter:translatedPoint];

  you can change  boundaries in above conditions

それが機能しているかどうかを教えてください...!!! 幸せなコーディング.!!!!

于 2012-11-01T13:04:09.770 に答える