35

Is it possible to show pushViewController animation look like presentModalViewController but that has background functionality of pushViewController?

Meet Doshi
  • 4,241
  • 10
  • 40
  • 81
sathish kumar
  • 1,061
  • 6
  • 16
  • 31

5 Answers5

57

If you want to a fade animation, this approach works.

CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:gridController animated:NO];
Thromordyn
  • 1,581
  • 4
  • 17
  • 45
steipete
  • 7,581
  • 5
  • 47
  • 81
49

Try this :

UIViewController *yourViewController = [[UIViewController alloc]init];

[UIView  beginAnimations: @"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: yourViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
jithinroy
  • 1,885
  • 1
  • 16
  • 23
25

For display PushViewConttroler animation as Present below code is working,

For Push

 ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
 CATransition* transition = [CATransition animation];
 transition.duration = 0.4f;
 transition.type = kCATransitionMoveIn;
 transition.subtype = kCATransitionFromTop;
 [self.navigationController.view.layer addAnimation:transition
                                                    forKey:kCATransition];
 [self.navigationController pushViewController:VC animated:NO];

And for POP

CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition
                                            forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];

There is 1 issue though, that its display light black background when its going up/down,
Working on that, As soon as its done post new code here.

Hardik Thakkar
  • 15,269
  • 2
  • 94
  • 81
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
  • @Julian, Not getting your Point. – Dilip Manek Aug 25 '15 at 07:27
  • @Dilip : Have you solved that display light black background when its going up/down issue?? If you have solved, then plz update your answer.. – Meet Doshi Jan 11 '16 at 05:12
  • 2
    @MeetDoshi, Sorry not able to solve this issue, but i have overcome this issue by setting colour of app window to my app theme, so that way its less noticeable. – Dilip Manek Jan 11 '16 at 05:29
  • As I have a monochromatic background, I got rid of the light black background with a little (dirty) for loop. Here you go in your origin VC: `for (UIView *view in self.view.subviews) { view.backgroundColor = someColor }` – pommefrite May 30 '16 at 08:06
1

For All Trying in Xamarin (C#) equivalent Code From Answer by @hardik Thakkar above, Has the issue of Black backgound during animation, rest all good.

For POP

    CATransition transition = CATransition.CreateAnimation();
    transition.Duration = 0.4;
    transition.Type = CAAnimation.TransitionReveal;
    transition.Subtype = CAAnimation.TransitionFromTop;
    this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));

For Push

    CATransition transition = CATransition.CreateAnimation();
    transition.Duration = 0.4;
    transition.Type = CAAnimation.TransitionReveal;
    transition.Subtype = CAAnimation.TransitionFromBottom;
    this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));
soan saini
  • 230
  • 3
  • 9
0

You should consider doing something like:

ViewController *myVC = [[ViewController alloc] initWithFrame:OFF_SCREEN];
[navigationController pushViewController:myVC animated:NO];

where OFF_SCREEN is some CGRect below the screen, like (0, 481, 320, 480). Then use an animation block to adjust the viewcontroller's view's frame.origin to be (0, 0). You would probably want to do the animate block in viewDidLoad or viewDidAppear.

kevboh
  • 5,207
  • 5
  • 38
  • 54