iOS View Animation

iOS View Transition Effect

animateWithDuration

Animation effect on changes to a view

  • Fade myView within 2 second
  • When the animation completed, remove the view completly
    [UIView animateWithDuration:2.0
                          delay:0.0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{ myView.alpha = 0.0; }
                     completion:^(BOOL fin) { if (fin) [myView removeFromSuperview]; }];
    

Move and animate the label to a CGPoint moveTo

  UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction;
  [UIView animateWithDuration:3.0 delay:0.0 options:options animations:^{
		label.center = moveTo;
  } completion:nil];

Rotate

  [UIView animateWithDuration:3.0 delay:0 options:options animations:^{
	label.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI);
  } completion:^(BOOL finished) {
	[UIView animateWithDuration:3.0 delay:0 options:options animations:^{
		label.transform = CGAffineTransformIdentity;
	} completion:nil];
  }];

transitionWithView

Create transition animation effect from one view to another

[UIView transitionWithView:self.view duration:1.0
        options:UIViewAnimationOptionTransitionFlipFromLeft
        animations:^{
          if (self.mapView.isHidden) {
	    self.view1.hidden = NO;
	    self.view2.hidden = YES;
	  } else {
	    self.view1.hidden = YES;
	    self.view2.hidden = NO;
	  }
	}
        completion:nil];