ios 如何更改presentViewController过渡动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32047415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change presentViewController Transition animation
提问by Stranger B.
I'm using presentViewController to change from a view to another without Navigation Controller like:
我正在使用 presentViewController 从一个视图更改为另一个没有导航控制器的视图,例如:
let HomeView = self.storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! ViewControllerHome
self.presentViewController(HomeView, animated:true, completion: nil)
How to change the transition? I want to the same animation like the Navigation controller.
如何改变过渡?我想要像导航控制器一样的动画。
I can use another transitions, but I don't find the transition I want here is the code I'm using
我可以使用其他过渡,但我在这里找不到我想要的过渡是我正在使用的代码
let HomeView = self.storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! ViewControllerHome
HomeView.modalTransitionStyle = UIModalTransitionStyle.PartialCurl
self.presentViewController(HomeView, animated:true, completion: nil)
回答by Mar-k
The answer of Mehul is correct but you can also do it the way you want it. With the instantiateViewController(withIndentifier: string)
Mehul 的答案是正确的,但您也可以按照自己的方式进行。使用instantiateViewController(withIndentifier: string)
This is how I do it:
这就是我的做法:
let destController = self.storyboard?.instantiateViewController(withIdentifier: "") as! YourViewController
destController.modalTransitionStyle = .flipHorizontal
self.navigationController?.present(destController, animated: true, completion: nil) // OR
let destController = self.storyboard?.instantiateViewController(withIdentifier: "") as! YourViewController
destController.modalTransitionStyle = .flipHorizontal
self.present(destController, animated: true, completion: nil)
回答by Mehul
For anyone doing this on iOS8, this is what I had to do:
对于在 iOS8 上执行此操作的任何人,这就是我必须做的:
I have a swift class file titled SettingsView.swift and a .xib file named SettingsView.xib. I run this in MasterViewController.swift (or any view controller really to open a second view controller)
我有一个名为 SettingsView.swift 的 swift 类文件和一个名为 SettingsView.xib 的 .xib 文件。我在 MasterViewController.swift 中运行它(或任何视图控制器真的打开第二个视图控制器)
@IBAction func openSettings(sender: AnyObject) {
var mySettings: SettingsView = SettingsView(nibName: "SettingsView", bundle: nil) /<--- Notice this "nibName"
var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CoverVertical
mySettings.modalTransitionStyle = modalStyle
self.presentViewController(mySettings, animated: true, completion: nil)
}