Question

Until now I have been using the code from this answer to simulate pushing a view. But now the view pushing animation changed. Does anyone have code to simulate the new animation?

Was it helpful?

Solution

I have found a way to simulate it, which is pretty pretty close to the original.

You have to add MTAnimation (which is needed for the exponential ease out). This library will need QuartzCore, so you will have to add it to your "linked libraries" in "build phases" within project settings if it isn't already added.

And here is the code:

push controller animation

// Get the views
UIView * fromView = sourceViewController.view;
UIView * toView = destinationViewController.view;
UIView *darkenView = [[UIView alloc] initWithFrame:fromView.frame];
[darkenView setBackgroundColor:[UIColor colorWithRed:255 green:255 blue:255 alpha:0]];
[fromView addSubview:darkenView];

// Get the size of the view area.
CGRect viewSize = fromView.frame;

// Add the new view to the old view.
[fromView.superview addSubview:toView];

// Position the new view outside of the screen
toView.frame = CGRectMake( viewSize.size.width , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
[UIView mt_animateViews:[NSArray arrayWithObjects:fromView, toView, nil]
               duration:.55
         timingFunction:MTTimingFunctionEaseOutExpo
                options:UIViewAnimationOptionAllowAnimatedContent
             animations:
    ^{
        // Animate the replacing of the views 
        fromView.frame =CGRectMake( -(viewSize.size.width/3) , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
        toView.frame =CGRectMake(0, viewSize.origin.y, viewSize.size.width, viewSize.size.height);
        [darkenView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.1]];
    }
                 completion:
    ^{
        // Remove the old view 
        [darkenView removeFromSuperview];
        [fromView removeFromSuperview];
    }];

pop controller animation (like with the back button)

// Get the views.
UIView * fromView = sourceViewController.view;
UIView * toView = destinationViewController.view;

// Get the size of the view area.
CGRect viewSize = fromView.frame;

// Add the new view to the old view.
[fromView.superview insertSubview:toView belowSubview:fromView];

// Position the new view outside of the screen
toView.frame = CGRectMake( -(viewSize.size.width/3) , viewSize.origin.y, viewSize.size.width, viewSize.size.height);

UIView *darkenView = [[UIView alloc] initWithFrame:toView.frame];
[darkenView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.1]];
[toView addSubview:darkenView];

[UIView animateWithDuration:0.35 delay:0 options:UIViewAnimationOptionAllowAnimatedContent animations:
^{
         // Animate the replacing of the views 
         fromView.frame =CGRectMake(viewSize.size.width , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
         toView.frame =CGRectMake(0, viewSize.origin.y, viewSize.size.width, viewSize.size.height);
         darkenView.frame = toView.frame;
         [darkenView setBackgroundColor:[UIColor colorWithRed:255 green:255 blue:255 alpha:0]];
}
                 completion:^(BOOL finished)
{
    if (finished)
    {
        // Remove the old view 
        [fromView removeFromSuperview];
        [darkenView removeFromSuperview];
    }
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top