【问题标题】:Is there any way to assign no UIModalTransitionStyle?有没有办法分配不 UIModalTransitionStyle?
【发布时间】:2015-02-20 09:41:02
【问题描述】:

我知道UIModalTransitionStyles 有四种类型,但我不想使用其中任何一种。

但是,此代码不起作用:

@IBAction func button(sender: AnyObject) {

    let modalView = ViewController()

    let storyboard = UIStoryboard(name: "Universal", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewController") as UIViewController
    modalView.modalTransitionStyle = nil // Error: type 'UIModalTransitionStyle' does not conform to protocol 'NilLiteralConvertible'

    self.presentViewController(vc, animated: true, completion: nil)

}

只要我没有指定modalTransitionStyle,编译器就会从UIViewController的Storyboard文档中得到modalTransitionStyle

如何设置不modalTransitionStyle

【问题讨论】:

  • 你如何展示这个modalView?你能显示更多代码吗?
  • @Wezly 我添加了更多代码。
  • @LordZsolt 感谢您的意见。它不是重复的,因为这个答案是用 Objective-C 编写的。
  • 我认为值得指出的是,在您的代码中,modalView 甚至没有被使用,您正在呈现的 vc 从情节提要中显示。

标签: ios swift uimodaltransitionstyle


【解决方案1】:

如果您不想要过渡,则应在展示新视图控制器时将 animated 属性设置为 false

self.presentViewController(vc, animated: false, completion: nil)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2012-04-24
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    相关资源
    最近更新 更多