1

I'm trying to write an app that uses custom animations to transition between view controllers in the view stack in a UINavigationController.

Right now, I'm adding multiple laters of the same view, just to get the mechanics up and running properly.

My visual goals are as follows:
1. Create a new "FirstVC".
2. Set the alpha value of [FirstVC view] to 0.
3. Set the transform value of [FirstVC view] to 25% in both directions (vertical & horizontal).

In the animations block, what I'd like to accomplish is:
1. Set the transform value of [OutgoingVC view] to 500% in both directions (blowing it up 5x).
2. Set the alpha value of [OutgoingVC view] to 0 (fading out to nothing).
3. Set the transform value of [FirstVC view] to 1 (bringing it back to its original size). 4. Set the alpha value of [FirstVC view] to 1 (fading in to full color).

The net effect of this animation should be that the "top page" blows up and fades out while the "next/bottom page" blows up (only to full screen) and fades in. The idea is of a user falling through a floor or something. "Going deeper."

I've slowed my animation down to a 10.0 sec interval so I can get a better handle of what's going on.

It appears that the animations taking place on "OutgoingVC" (i.e., the top view) are correct. The bottom view, however, seems to come in fine (100% of screen size and alpha=1.0), but then it keeps going and appears to blow up to either 4x/5x and also fade out to an alpha of 0. Once the screen has gone completely black, the new UIViewController (FirstVC) is correctly displayed on screen.

Does anyone see why my code wouldn't behave the way I want?

Thanks!


Stupid me! Here's the code:

- (IBAction)AddNewScreenPressed:(id)sender 
{
    FirstVC *newViewController = [[FirstVC alloc] init];
    UIView *currentView = [self view];
    UIView *newView = [newViewController view];
    [newView setTransform:CGAffineTransformMakeScale(0.25, 0.25)];
    [newView setAlpha:0];
    [UIView transitionWithView:[self view]
                      duration:10.0
                       options:UIViewAnimationOptionCurveEaseInOut
                    animations:^{
                        [[self view] addSubview:newView];
                        [currentView setAlpha:0];
                        [currentView setTransform:CGAffineTransformMakeScale(5.0, 5.0)];
                        [newView setAlpha:1.0];
                        [newView setTransform:CGAffineTransformMakeScale(1, 1)];
                    }
                    completion:^(BOOL finished){
                        [[self navigationController] pushViewController:newViewController animated:NO];
                    }
     ];
}

2 Answers 2

1

You have added newView as a subview of currentView, so perhaps the animations you are doing to currentView also apply to newView - it presumably scales up and changes the alpha of its subviews as well, including newView. Could you have the initial scale of newView to be 0.2, and drop the rescaling of newView in the animation block, so it would end up at 1.0 scale? Not sure what to do about the alpha, though...

EDIT after seeing your solution below - glad you've got it working, would it perhaps be cleaner (if you're grabbing images off the screen to handle your views anyway) to have a separate viewcontroller to manage the transition, passing it the two images so it can do the animations internally, so you push it to the front with no animation, perform your animation starting with the first view's image and ending with the second view's image (so you can just do standard animations on two imageViews instead of the whole view of the controller), and then push the second view controller once you are done?

1
  • The final solution for this was to use segues in iOS 5 Beta. I'm not sure I can comment more for now, but your EDIT is close in theory to what I've implemented. Thus, your answer is accepted!
    – mbm29414
    Commented Aug 23, 2011 at 14:24
1

After playing with it some more, I've gotten over one hump and met with another obstacle.

I'm upvoting jrturton's answer because the problem did indeed seem related to the fact that I was adding the new view to [self view].

What I did to get around this was add a buffer view ([self BackView]) that exists between [self view] and its subviews.

Then, then following code works to push a new view controller:

- (IBAction)AddNewScreenPressed:(id)sender 
{
    FirstVC *newViewController = [[FirstVC alloc] init];
    UIView *newView = [newViewController view];
    [newView setAlpha:0];
    [newView setTransform:CGAffineTransformMakeScale(0.25, 0.25)];
    [[self view] addSubview:newView];
    [UIView transitionWithView:[self view]
                      duration:1.0 
                       options:UIViewAnimationOptionCurveEaseInOut
                    animations:^{
                        [[self BackView] setTransform:CGAffineTransformMakeScale(5, 5)];
                        [[self BackView] setAlpha:0];
                        [newView setTransform:CGAffineTransformMakeScale(1, 1)];
                        [newView setAlpha:1];
                    }
                    completion:^(BOOL finished){
                        [newView removeFromSuperview];
                        [[self navigationController] pushViewController:newViewController animated:NO];
                        [[self BackView] setTransform:CGAffineTransformIdentity];
                        [[self BackView] setAlpha:1];
                    }
     ];
}

Now, of course, I've run into another problem, namely, popping controllers.

When I pop them, the animation seems to work just fine, but when I get to the end (completion block) and do the following:
[[self navigationController] popViewControllerAnimated:NO];
or even:
[[self navigationController] popViewControllerAnimatedYES];
what I end up with is a blank white screen.

I'm assuming that something I'm doing during my "push animation" is causing this problem, but I can't figure it out! Help!

Thanks!

1
  • Turns out that I can do what I want by grabbing an image of the view to "reveal" and animating using that image ([[UIImageView alloc] initWithImage:highlightedImage:]). Then, popping works just fine.
    – mbm29414
    Commented Aug 8, 2011 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.