2012-10-29 5 views
0

하위 뷰로 고정 된 개수의 미리보기 이미지가있는 스크롤보기가 있습니다. 다른 뷰에서이 이미지를 터치하여 사각형으로 옮기고 싶습니다. 나는 scrollview (즉, 동일한보기를 따라)를 따라 이미지를 움직일 수 있지만 다른보기를 가로 질러 움직일 수는 없다. 이제 터치 위치에 따라 이미지의 중심을 변경합니다. 터치 포인트가 스크롤 뷰 프레임을 넘어서 증가하면 이미지가 사라집니다. 이것은 내 문제입니다터치로 이미지 이동

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
     UITouch *touch = [[event allTouches] anyObject]; 

     CGPoint location = [touch locationInView: self]; 
     NSLog(@"%f,%f",location.x,location.y); 
     touch.view.center = location; 

    } 

이 문제에 대한 해결책은 저에게 큰 도움이 될 것입니다 !!!

는 작업으로 다음 handlePan: 방법으로, 각 이미지에 panGestureRecognizer을 추가

자세한 내용 enter image description here

+0

'UIPanGestureRecognizer' –

+0

코드를 입력하십시오. 지금까지 이미지를 어떻게 움직였습니까? – rdurand

+0

@rdurand 코드를 추가하십시오. –

답변

1
여기

내가 할 줄 무엇인가에 대한 이미지를 참조하시기 바랍니다. 올바른 imageView (myImageView)를 얻는 방법을 알아 내야하지만 이미지가 손가락을 따라 가게됩니다.

- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer { 

    // Find the correct image you're dragging 
    // UIImageView *myImageview = ... 

    CGPoint translation = [recognizer translationInView:self.view]; 

    if (recognizer.state == UIGestureRecognizerStateEnded) { 
     // What to do when you start the gesture 
     // You may also define myImageView here 
     // (if so, make sure you put it in @interface, 
     // because this method will be called multiple times, 
     // but you will enter this "if" only when you start the touch) 
    } 

    // Keep your image in the screen 
    if (myImageView.frame.origin.x + translation.x >= 0.0f && 
     myImageView.frame.origin.x + myImageView.frame.size.width + translation.x <= 320.0f && 
     myImageView.frame.origin.y + translation.y >= 0.0f && 
     myImageView.frame.origin.y + myImageView.frame.size.height + translation.y <= 480.0f) { 

     myImageView.center = CGPointMake(myImageView.center.x + translation.x, 
             myImageView.center.y + translation.y); 

    } 

    if (recognizer.state == UIGestureRecognizerStateEnded) { 
     // What to do when you remove your finger from the screen 
    } 

    [recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; 
}