2016-07-20 7 views
0

뷰에서 UIImage를 이동 중입니다. 이제 이미지가 새로운 위치로 옮길 때 그 이미지를 그 위치에 보관하고 배열에 저장하려고합니다. 이것을 어떻게 할 수 있습니까?UIPanGesture를 사용하여 Objc의 UIView에서 새 위치로 이동 한 이미지의 위치를 ​​저장하십시오.

팬 제스처를 사용하여 이미지를 이동시키기위한 코드는 : -

- (void) handlePan: (UIPanGestureRecognizer *) recogniser { 
    CGPoint point = [recognizer locationInView:_backImage]; 

    //Only allow movement up to within 100 pixels of the right bound of the screen 
    if (point.x < [UIScreen mainScreen].bounds.size.width - 100) { 

     CGRect newframe = CGRectMake(point.x, point.y, smallImageViewWidth, smallImageViewHeight); 
     _centreImage.frame = newframe; 
    } 
} 
+0

내 대답 –

답변

0

가 VC 한 글로벌 배열을 유지하고라는

있는 NSMutableArray * arrImagePositions = [NSMutableArray의 어레이 즉; 당신의 방법에서

당신은 해결 ..

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

    CGPoint point = [recognizer locationInView:_backImage]; 

    //Only allow movement up to within 100 pixels of the right bound of the screen 
    if (point.x < [UIScreen mainScreen].bounds.size.width - 100) { 

    CGRect newframe = CGRectMake(point.x, point.y, smallImageViewWidth, smallImageViewHeight); 
    _centreImage.frame = newframe; 

    //store all location where you moved your image in array 
     if(gestureRecognizer.state == UIGestureRecognizerStateEnded){ 
      [arrImagePositions addObject: newframe]; 
     //store here in your array. 
     } 
    } 
    } 
} 
+0

thnku를 확인이 배열에서 해당 위치를 저장할 수 있습니다! – iosLearner

+0

도와 드리겠습니다 ... 답변을 찾은 경우 도움이된다면 다른 사람들을 받아주십시오. :) –