---
title: "swift 代码打开和关闭一个storyboard 页面"
author: "2014马年"
date: "2016-03-12T14:19:25Z"
tags: []
categories: ["移动开发"]
slug: "swift-storyboard"
draft: false
lastmod: "2016-03-12T14:43:43Z"
id: 2282362
url: "https://20142014.iteye.com/blog/2282362"
---

1.在storyboard里创建一个ViewController

 

![](http://dl2.iteye.com/upload/attachment/0115/7342/5b17583f-75e9-3579-9cae-81a1ea84423b.png)  
 

 

2.写入如下代码

 

```
            print("弹出登录框")
            let loginViewController  = self.storyboard?.instantiateViewControllerWithIdentifier("login_view") as! LoginViewController
            presentViewController(loginViewController, animated: true, completion: nil)
```

 

3.LoginViewController.swift

```
import UIKit

class LoginViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}
```

 

4.关闭

```
self.dismissViewControllerAnimated(true, completion: nil)
```

 

 

结束