0

我设置了一个 imageView,并UIView在该 imageView 上添加了一个。这UIView是透明的,现在我正在动态添加更多ImageViews内容UIView

我想在我动态添加的 ImageViews 上设置 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 回答