Push ViewController with modal animation (horizontal flip)
I need to push a view controller to another view controller.
menuVC -> VC1 ->VC2
going from menuVC to VC1 does not require animation, but going from VC1 to VC2 and from VC2 to VC1 requires flip animation to occur.
However, when switching from VC2 to menuVC, no animation is required.
I am using the following code:
(from how to click viewController with flip animation )
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
FlashCardVC *flashCardVC = [[FlashCardVC alloc] init];
[self.navigationController pushViewController:flashCardVC animated:NO];
[UIView commitAnimations];
The screen disappears completely when I try to do this.
What's wrong?
source to share
You should now be using block based animation. Also, if you create a storyboard controller from a controller that is also in the same storyboard, you can more easily access that storyboard using self.storyboard.
-(IBAction)flipToNext:(id)sender {
SecondController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"Next"];
[self.navigationController pushViewController:next animated:NO];
[UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
}
source to share
Great answer: Displaying the pushviewcontroller animation looks like presentModalViewController
(code)
//UIViewController *yourViewController = [[UIViewController alloc]init];</s>
[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];
However, this also created a blank screen.
Instead, if you are using storyboards, your best bet is to instantiate through the storyboard:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle bundleForClass:[self class]]];
YourViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerID"];
yourViewControllerID is set in the storyboard under the identity inspector for the yourviewcontroller class.
source to share
Use these extensions in Swift 4.2
For controller push and pop view with horizontal flipped animation
extension UINavigationController {
func pushViewControllerWithFlipAnimation(viewController:UIViewController){
self.pushViewController(viewController
, animated: false)
if let transitionView = self.view{
UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromLeft, animations: nil, completion: nil)
}
}
func popViewControllerWithFlipAnimation(){
self.popViewController(animated: false)
if let transitionView = self.view{
UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromRight, animations: nil, completion: nil)
}
}
}
source to share