开发者

Problems moving animation to iOS4 blocks

开发者 https://www.devze.com 2023-01-10 04:17 出处:网络
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

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


do: options:UIViewAnimationOptionTransitionCurlUp instead of: options:UIViewAnimationTransitionCurlUp

That is why your code works now :).


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);
                }];


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消