2016-07-20 14 views
0
verschoben

Ich bin UIImage in einer Ansicht verschieben. Jetzt, wenn das Bild an eine neue Position verschoben wird, möchte ich dieses Bild in dieser Position behalten und das in einem Array speichern. Wie kann ich das erreichen?Mit UIPanGesture speichern Sie den Speicherort des Bildes an einen neuen Speicherort in der UIView in Objc

Der Code für Bewegtbild Pan Geste verwendet, ist: -

- (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

meine Antwort –

Antwort

0

ein globales Array in Ihrem VC halten und benannt, dass

NSMutableArray * arrImagePositions = [NSMutableArray-Array];

in Ihrer Methode können Sie diese Position in diesem Array speichern

- (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 überprüfen .. gelöst! – iosLearner

+0

Glücklich zu helfen ... Wenn Sie die Antwort gefunden haben, ist hilfreich, dann akzeptieren Sie bitte für andere. :) –