2012-10-20 16 views
0

하나의 imageView를 설정하고 해당 imageView에 UIView을 추가했습니다. UIView은 투명합니다. 이제 UIView에 동적으로 ImageViews을 추가하고 있습니다.특정보기 내에서 제스처 인식기를 제한하는 방법

내가 동적으로 추가하는 ImageViews에서 팬 및 핀치 줌 제스처 인식기를 설정하려고하지만 제스처 인식기 작동 범위를 제한 할 수있는 방법을 얻지 못합니다.

팬 제스처를 사용하여 드래그 한 이미지는 UIView 안에 머물러 야하고 UIView의 경계 밖으로 드래그해서는 안됩니다.

UIView은 화면의 절반 만 차지합니다.

어떻게하면이 아이디어를 얻을 수 있습니까?

답변

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 

...이 작동되지 않거나 알려줘! 해피 코딩. !!!!

+0

안녕하세요, 감사합니다.하지만 touchesMoved 메소드를 사용하여 달성했습니다. :) – Shailesh

관련 문제