您的位置:首页 > 移动开发 > Swift

Swift实现IOS界面的跳转

2017-09-28 15:40 344 查看
IOS开发中界面跳转有两种方式,上下跳转和左右跳转。

上下跳转_TO:

[objc] view
plain copy

 print?

let secondViewController = SecondViewController()  

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

上下跳转_BACK:

[objc] view
plain copy

 print?

dismissViewControllerAnimated(true, completion: nil)  

-----------------------------------------------

-----------------------------------------------

左右跳转_TO:

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

[objc] view
plain copy

 print?

let secondViewController = SecondViewController()  

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

左右跳转_BACK:

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

( - ) BACK_到上一级:

[objc] view
plain copy

 print?

let firstViewController = FirstViewController()  

self.navigationController?.popViewControllerAnimated(true)  

( - ) BACK_指定界面:

[objc] view
plain copy

 print?

// 获得视图控制器中的某一视图控制器  

let viewController = self.navigationController?.viewControllers[0]  

self.navigationController?.popToViewController(viewController as! UIViewController, animated: true)  

( - ) BACK_根视图:

[objc] view
plain copy

 print?

self.navigationController?.popToRootViewControllerAnimated(true)  

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

[objc] view
plain copy

 print?

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  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: