title: Preserve Variable in a method
body: <p>This should be easy.</p>
  
  <p>I've got a method to move a view up and down and while doing so I move a UIButton over and down... then move the button back to its original position when the method runs again.</p>
  
  <p>I thought I could get the original position of the button with float originalCenterX = topSubmitButton.center.x and float originalCenterY = topSubmitButton.center.y but of course those are overwritten with the center of the button when the method is hit for the second time.</p>
  
  <p>How does one preserve a variable over multiple iterations of a method?</p>
  
  <pre><code>-(IBAction)scrollForComment { 
  
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationDuration:0.5]; 
  
  CGRect rect = self.view.frame;
  
  NSLog(@"button center x = %f y = %f",topSubmitButton.center.x,topSubmitButton.center.y);
  float originalCenterX = topSubmitButton.center.x;
  float originalCenterY = topSubmitButton.center.y;
  
  if (commentViewUp) {
      rect.origin.y = self.view.frame.origin.y + 80;// move down view by 80 pixels
      commentViewUp = NO;
  
      CGPoint newCenter = CGPointMake( 57.0f , 73.0f); // better to calculate this if you are going to rotate to landscape
  
      [UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:0.5f];
      topSubmitButton.center = newCenter;
      [UIView commitAnimations];
  
  } else { // toggling the view's location
      rect.origin.y = self.view.frame.origin.y - 80;// move view back up 80 pixels
      commentViewUp = YES;
  
  
      CGPoint newCenter = CGPointMake(160 , 74.0f + topSubmitButton.center.y);// would like to calculate center
      [UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:0.5f];
      topSubmitButton.center = newCenter;
      [UIView commitAnimations];
    }
  
  self.view.frame = rect;
  
  [UIView commitAnimations];
  
  }
  </code></pre>
  
  <p>Bonus if you can tell me how to put the center of a view in a CGPoint's x value.</p>