How To Push View Controller From Left And Pop From Right

So, have you ever wondered if there is a way to push your view controller from left to right, and then pop it from right to left. The default pushing of view controllers in iOS is from the opposite (Right To Left), right? haha!

Ok, my CTO gave me a code which I can use to present a viewcontroller from wherever I like to wherever I like. Meaning, from bottom to top, right to left, and etc... But then, the code which he gave uses a PRESENT VIEW CONTROLLER. I need a push to retain the Navigation Controller or Navigation Bar. And then one time, when we were at a certain bar to drink some beer and eat, I found out a blog. From: kiranjasvanee

FOR PUSHING THE VIEWCONTROLLER FROM LEFT TO RIGHT:
CATransition* transition = [CATransition animation];
    transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype= kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
NameViewController *controller = [[NameViewController alloc] init];
    [self.navigationController pushViewController:controller animated:NO];


FOR POPPING THE VIEWCONTROLLER FROM RIGHT TO LEFT:
CATransition* transition = [CATransition animation];
    transition.duration = .45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionMoveIn;
    transition.subtype= kCATransitionFromRight;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
     
    [self.navigationController popViewControllerAnimated:YES];

If you find this tutorial helpful, please share and subscribe!

1 comments:

Thanks for sharing this post. Your post is really very helpful its students. iPhone online course

Reply

Post a Comment