2016-07-20 9 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に1つのグローバル配列を維持し、名前の

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

喜んでお手伝いします...あなたが答えを見つけたら、他の人に受け入れてください。 :) –

関連する問題