Make UIModalTransitionStyle See How To Fast To Press
I would like to know if there is a way to make the UIModalTransitionStyle "push"?
Because I have something like this:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let secondViewController = storyBoard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
secondViewController.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
self.presentViewController(secondViewController, animated:true, completion:nil)
But I would like to have a simple "push" effect when I switch to another view controller.
Respectfully!
EDIT (thanks to LoGoCSE) But still not resolved
Now I have
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let secondViewController = storyBoard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
secondViewController.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
let transition: CATransition = CATransition()
transition.duration = 0.25
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
self.view.layer.addAnimation(transition, forKey: kCATransition)
self.presentViewController(secondViewController, animated:false, completion:nil)
But the point is, adding the view ( [self.view addSubview:destinationController.view];
) doesn't work. So I tried to present the ModalView as usual (no animation) but the transition is done on the same view and then the second view appears.
+3
source to share
1 answer
-This code works in Objective-C. You just need to convert it to Swift
UIViewController *sourceViewController = self ;
UIViewController *destinationController = objdestinationViewController;
CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush; //kCATransitionMoveIn; //,kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft,kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:kCATransition];
[self.view addSubview:destinationController.view];
Hope it works :)
+1
source to share