5
votes

I'm currently performing a curl up animation by doing the following:

CATransition *animation = [CATransition animation];
animation.type = @"pageCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.duration = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[[self.view.window layer] addAnimation:animation forKey:nil];

This animation will simply perform a page curl animation but in the end you are left looking at the same view that you started out with. No REAL transition ever occurred.

Now using animation blocks I know you can do something to the effect of:

[UIView transitionFromView:self.view
                    toView:aNewView    // a view to transition to
                  duration:1 
                   options:UIViewAnimationTransitionCurlUp|UIViewAnimationOptionCurveEaseIn
                completion:NULL];

However, using animation blocks you are transitioning to a new view, aNewView, which is different from the CATransition animation above which reuses the same view (no real transition ever occurs). The problem with the animation block is that you have to actually create the new view to transition to which is cumbersome in my case because the view is rather complicated and I'd rather not create a UIView subclass.

Is there a way to perform the above CATransition animation using animation blocks while getting around the difficulties of having to rebuild a view or create a custom subclass?

1
Couldn't you just do [UIView transitionFromView:self.view toView:self.view...?Letrstotheprez
Nope. The view gets removed for some reason and the screen is blackJake Vizzoni
I think you could try [UIView transitionFromView:self.view toView:[self.view copy]...Letrstotheprez
Unfortunately UIView doesnt implement the copying protocol. Good idea though. I wish it workedJake Vizzoni
I thought it might not, I wasn't really in a position to check very well so I didn't post it as an answer.Letrstotheprez

1 Answers

3
votes

Ok - so I figured it out for anyone who is interested. It's actually super simple. You can simply use the method: transitionWithView:duration:options:animations:completion:

For example:

[UIView transitionWithView:self.view
                  duration:1
                   options:UIViewAnimationOptionTransitionCurlUp|UIViewAnimationCurveEaseIn
                animations:^{ // do anything you want here } 
                completion:NULL];

That's it. This will show a transition animation back to the same view. You can make any changes you want to the new view (maybe display some new text, whatever...) in the animation block.

I hope this helps someone out down the line...