Question

So I have a simple application set up to teach myself animations in iOS. So all I have currently is a UIView that's hooked up to a tap gesture recognizer. So when you tap the view, it implements this method:

-(IBAction)startAnimation:(id)sender
{
    [UIView animateWithDuration:3.0 animations:^{
          tabView.center = CGPointMake(tabView.center.x, tabView.center.y + 60);
    }];
  //if tapped again, go back to original y coordinate 
}

My question is how do I set it back to the original y coordinate position it came from upon an additional tap?

Was it helpful?

Solution

Try this:

// just my example
int i = 0; // static variable
-(IBAction)startAnimation:(id)sender
{
i++;
[UIView animateWithDuration:3.0 animations:^{
      if(i%2==1)
       tabView.center = CGPointMake(tabView.center.x, tabView.center.y + 60);
      else
       tabView.center = CGPointMake(tabView.center.x, tabView.center.y - 60);
}];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top