Block transition with more than one view
up until now I used the begin/commit method to switch between views. Going this way it was easily possible to "combine" two or more views to be inserted on top at the same time. In my case it's a content2.view with a border2.view over it. The animation looked like it is one view with the content in a frame.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:speed];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
[window addSubview:开发者_如何学Ccontent2.view];
[window addSubview:border2.view];
[UIView commitAnimations];
content1.view = nil;
Now I wanted to convert the animations into blocks. It also works, but not I can't figure out how I can "merge" two views. Is there a way?
[UIView transitionFromView:content1.view
toView:content2.view
duration:2.0
options:UIViewAnimationOptionTransitionFlipFromRight
completion:NULL];
You have to use the method:
transitionWithView:duration:options:animations:completion:
transitionFromView:toView is a convenience method for the most general case of needing to transition from one view to another view.
In this case, your code should be
[UIView transitionWithView:window
duration:2.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{ [window addSubview:content2.view];
[window addSubview:border2.view]; }
completion:^(BOOL completed){ [content1.view removeFromSuperview];
content1.view = nil; }
精彩评论