Block Animations

| Comments

Hey there,

I’m still developing the iOS application for my diploma thesis, so I will try to post some code snippets regularly. Anyways since iOS it is encouraged to use block animations instead of “Animating Views” methods. The framework offers two transitions between UIViews: Curl and Flip. They can be easily activated through

[UIView transitionFromView:oldView toView:newView duration:1.0 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
/* on complete callback */
}];


If you want to do something more advanced like sliding a View from a side you can use a block animation, for that case I wrote a method

-(void)showWithAnimationSlideToLeft:(UIViewController*)rootViewController from:(UIView*)fromView to:(UIView*)toView
{
toView.view.frame = CGRectMake(fromView.frame.size.width, 0, rootViewController.view.frame.size.width, rootViewController.view.frame.size.height);
[rootViewController insertSubview:toView belowSubview:fromView];
[UIView animateWithDuration:0.5 animations:^{
toView.frame = CGRectMake(0, 0 rootViewController.view.frame.size.width, rootViewController.view.frame.size.height);
fromView.frame = CGRectMake(-fromView.frame.size.width, 0, rootViewController.view.frame.size.width, rootViewController.view.frame.size.height);
} completion:^(BOOL finished){
[fromView removeFromSuperview];
}];
}


Hopefully this is helpful for you guys!

Copyright © 2014 - Damien Antipa. Powered by Octopress