我想知道是否可以使UIModalTransitionStyle具有“推送”样式?
因为我有这样的事情:
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)
但是当我移到另一个viewcontroller时,我希望具有简单的“推”效果。
问候 !
编辑(感谢LoGoCSE)但仍未解决
我现在有
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)
但是,重点是,添加视图(
[self.view addSubview:destinationController.view];
)不起作用。因此,我尝试像往常一样呈现ModalView(不带动画),但是在同一视图上完成了过渡,然后出现了第二个视图。
最佳答案
-Objective-C中的此代码有效。您只需将其转换为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];
希望它能工作:)
关于ios - 使UIModalTransitionStyle看起来像快速推送,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31287059/