A container view controller that defines a stack-based scheme for navigating hierarchical content.
To dismiss a modally presented view controller, call the view controller's dismiss(animated:completion:) method.
What is a navigation stack? “A navigation controller object manages its child view controllers using an ordered array, known as the navigation stack. The first view controller in the array is the root view controller and represents the bottom of the stack.
To flip into a view controller:
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:viewController animated:YES completion:nil];
To flip out of it:
[self dismissViewControllerAnimated:YES completion:nil];
This is how I'm doing it:
AboutShowViewController *aboutShowViewController = [[AboutShowViewController alloc] initWithNibName:@"AboutShowViewController" bundle:[NSBundle mainBundle]];
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:aboutShowViewController animated:YES];
[UIView commitAnimations];
[aboutShowViewController release];
Credit goes to faysar here.
There is a fundamental flaw in your understanding of the MVC structure in Cocoa Touch, which is, View Controllers and Views are comparable and similar. The truth is, they are Not.
Back to your specific question, yes, animations are based on views, not on view controllers. But each view should be controlled by one of your view controllers. And this which-view-belongs-to-which-controller thing is totally up to you. In your case, animation could happen between 2 views with 2 different controllers, or, they could also happen between 2 views of the same controller.
As for code samples, I suggest you take a look at one of Xcode's default templates, the Utility Application, which has implemented this click-and-flip animation in a succinct and standardized way.
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
// for back button
changeTransition()
}
//btnMap.addTarget(self, action: #selector(searchHotelsResultVC.goToMap), for: .touchUpInside)
//btnMap.addTarget(self, action: #selector(MapViewController.backToList), for: .touchUpInside)
func goToMap() {
// for pushing
changeTransition()
navigationController?.pushViewController(settingsVC, animated: false)
}
func backToList() {
// for dismiss
changeTransition()
navigationController?.popViewController(animated: false)
dismiss(animated: true, completion: nil)
}
func changeTransition() {
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
//transition.type = kCATransitionPush
transition.type = "flip"
transition.subtype = kCATransitionFromLeft
navigationController?.view.layer.add(transition, forKey: kCATransition)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With