IPhone: Transition Using Core Animation

On Mac, the best way to easily cross-over between views (without any user-defined keyframe timing) is to do something like the following snippet:

[[self animator] replaceSubview:aView with:bView];

      

Unfortunately the animator property is not available on iPhone. What's the best thing to do on iPhone? Is setting alpha channels on each view? Sample code would be great.

Thanks.

+1


a source to share


1 answer


The main way to animate views on the iphone is using the beginAnimations and commitAnimations UIView calls. They allow you to change the animation properties of a view and animate those changes.

For example, I have a custom view that is hidden and shown using this approach:

- (void) showAView:(CustomAView *)aView
{
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.5];    
  aView.frame = CGRectMake(0.0f, 110.0f , aView.frame.size.width, aView.frame.size.height);
  [UIView commitAnimations];  
}

- (void) hideAView:(CustomAView *)aView
{
  [UIView beginAnimations:nil context:nil];
  [UIView setAnimationDuration:0.5];  
  aView.frame = CGRectMake(0.0f, self.view.frame.size.height, aView.frame.size.width, aView.frame.size.height);    
  [UIView commitAnimations];
}

      



By wrapping the frame property change in a beginAnimations / commitAnimations UIView, the change has a standard animation applied to it.

You can add additional animation properties using methods of the UIView animation class, for example.

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

      

0


a source







All Articles