【问题标题】:How to change segue kind programmatically?如何以编程方式更改 segue 类型?
【发布时间】:2016-03-04 14:45:40
【问题描述】:

如何以编程方式更改在情节提要中创建的转场类型?

我想根据设备类型更改 segue 类型。对于.phone,应该执行类型为“show”(推送)的故事板segue。对于.pad,我想将 segue 类型更改为“modal”。

我应该在prepareForSegue 中执行此操作,还是必须停止在shouldPerformSegueWithIdentifier 中执行转场并手动执行模态转场?

编辑:这个问题的重点是改变 segue 类型,而不是如何识别设备类型。

【问题讨论】:

  • 你找到答案了吗?

标签: swift segue


【解决方案1】:

试试这个:

enum UIUserInterfaceIdiom : Int {
    case Unspecified
    case Phone // iPhone and iPod touch style UI
    case Pad // iPad style UI
}

viewDidLoad()

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("vc2") as! myViewController

    switch UIDevice.currentDevice().userInterfaceIdiom {

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

    case .Pad:
      self.showViewController(vc, sender: nil)
        break
    case .Unspecified:
        // Do something
        break
    default:
       // Do something
    }

【讨论】:

  • 谢谢 Led,我知道如何识别设备类型。我想知道如何改变segue。也许我的帖子中没有说清楚,我会更新它。
  • @Manuel 你可能对 presentViewController() 和 showViewController() 函数感兴趣
猜你喜欢
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
  • 2023-04-10
  • 1970-01-01
  • 2016-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多