码迷,mamicode.com
首页 > 移动开发 > 详细

Swift实现IOS界面的跳转

时间:2017-06-01 12:07:13      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:view   ati   blog   smi   com   miss   class   ptov   左右   

iOS开发中界面跳转有两种方式,上下跳转和左右跳转。

下跳转_TO:

let secondViewController = SecondViewController()  
self.presentViewController(secondViewController, animated: true, completion: nil)  

 上跳转_BACK:

dismissViewControllerAnimated(true, completion: nil)  

 右跳转_TO:

(将新的视图控制器PUSH到navigationController中,相当于入栈操作)

let secondViewController = SecondViewController()  
self.navigationController!.pushViewController(secondViewController, animated: true) 

 左跳转_BACK: 

(将当前视图控制器从导航视图控制器堆栈中移除,从而返回到了上一级界面)

( - ) BACK_到上一级:

let firstViewController = FirstViewController()  
self.navigationController?.popViewControllerAnimated(true)  

( - ) BACK_指定界面: 

// 获得视图控制器中的某一视图控制器  
let viewController = self.navigationController?.viewControllers[0]  
self.navigationController?.popToViewController(viewController as! UIViewController, animated: true)  

 ( - ) BACK_根视图:

self.navigationController?.popToRootViewControllerAnimated(true) 

 根视图的设置需要在AppDelegate中设置:

var window: UIWindow?  
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool  
{  
    var firstViewController = FirstViewController()  
    var rootNavigationViewController = UINavigationController(rootViewController: firstViewController)  
          
    self.window!.rootViewController = rootNavigationViewController  
          
    return true  
}  

 

Swift实现IOS界面的跳转

标签:view   ati   blog   smi   com   miss   class   ptov   左右   

原文地址:http://www.cnblogs.com/niuni-623/p/6927969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!