views:

172

answers:

4

I have a working view animation, that curls up a container view, while the containerview.subviews changes. (before the animation a UITableView will be shown, after it is a custom view, name keypadView)

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp 
                       forView:containerView 
                         cache:YES];
[secondView removeFromSuperview];
[containerView addSubview:keypadView];
[UIView commitAnimations];

Now I want to rewrite this code for the iOS4 block-based api, as I want to use the completion block. I wrote this:

[UIView transitionWithView:containerView
                  duration:.75 
                   options:UIViewAnimationTransitionCurlUp
                animations:^{
                    NSLog(@"Hey Ho");
                    [secondView removeFromSuperview];
                    [containerView addSubview:keypadView];
                } 
                completion:NULL];

The views switch — but not animated.

what is wrong with my code?

Edit

completion: ^(BOOL completed){
    NSLog(@"completed %d", completed);
}

doesn't help, as NULL is an accepted value, according to the docs

+1  A: 

Did you leave [UIView beginAnimations:nil context:nil]; above your new block?

jessecurry
No, I didn't leave it
vikingosegundo
+1  A: 

Is the completion block always NULL? Try putting an NSLog statement in there or something. I don't know if NULL blocks would mess it up.

Jeff Kelley
please see my edit
vikingosegundo
+1  A: 

The sample in the UIView class reference may be wrong - or maybe there's a bug with adding and removing views in the animations block object, but the only way I've been able to get it to work is as follows:

[secondView removeFromSuperview];
[containerView addSubview:keypadView];
[UIView transitionWithView:containerView
                  duration:.75
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^{}
                completion:^(BOOL finished) {
                    NSLog(@"finished %d", finished);
                }];
Gordon Hughes
thanks for the answer, but this code doesnt work for me neither.
vikingosegundo
Woops! The block animation options should use `UIViewAnimationOption` instead of `UIViewAnimationTransition`. So the correct animation option is `UIViewAnimationOptionTransitionCurlUp`. Edited my answer to fix that. Sorry :)
Gordon Hughes
Gordon Hughes
A: 

do: options:UIViewAnimationOptionTransitionCurlUp instead of: options:UIViewAnimationTransitionCurlUp

That is why your code works now :).

Tiago Alves
yeah, this was the problem. I found it weeks ago but I forgot to write an answer.
vikingosegundo