通過segue跳轉到的界面,都是一個新的實例而不是之前的界面!!!傳值的時候尤其要記得,不然會出現明明傳值了,但是到對應界面卻發現,傳過來的值沒有了!?
多個場景之間切換樣式(kind):
Show(e.g. Push):和Push不同,哪怕不在Navigation下面也可以通過Show跳轉過去。但是必須在啟用Size Class。
Show Detail(e.g. Replace)
Present Modally
Resend As Popover
Deprecated Segue:
Push:跳轉到一個新的視圖,可以前后移動,用于導航視圖控制器;(必須在NavigationController中使用,不然跳轉時會Crash!)
Modal:過渡到另一個場景,用于完成某項任務,完成后關閉并返回;(返回方法一般采用DismissViewController())
Popover
Replace
Segue過渡類型(modalTransitionStyle):
是從一個場景切換到另一個場景時播放的動畫。一般用默認的就好了。
Cover Vertical -- 新場景從下向上移動,逐漸覆蓋舊場景。
Flip Horizontal?-- 視圖水平翻轉,以顯示背面的新場景。
Cross Dissolve?-- 舊場景淡出,新場景淡入。
Partial Curl?-- 舊場景像書頁一樣翻開,顯示下面的新場景。
Segue顯示樣式(modalPresentationStyle):
它決定了模態視圖在屏幕上的顯示方式,(只在iPad應用程序中)
Form Sheet(表單) -- 將場景調整到比屏幕小(不管朝向),并在當前場景后面顯示原始場景,這幾乎相當于在一個iPad窗口中顯示。
Page Sheet(頁面)?-- 調整場景大小,使其以縱向格式顯示。
Full Screen(全屏)?-- 調整場景大小,使其覆蓋整個屏幕。
Current Context(當前上下文)?-- 以原始場景的顯示方式展示場景。
Segue跳轉方式:
跳轉到一個新的界面實例:
1、在StoryBoard中拖動連接到對應的controller中即可;
2、在Action的事件中添加preformSegueWithIdentifier();
3、靜態代碼跳轉:
@IBActionfuncback(sender:UIButton) {
//1、獲取Main StoryBoard;
? ?let mainStoryBoard =UIStoryboard.init(name:"Main", bundle:nil)
//2、獲取目標Controller的identifier
? ?let newViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("view1") as! ViewController
//3、設置跳轉樣式;
? ? ? ? newViewController.modalTransitionStyle=UIModalTransitionStyle.CoverVertical
//4、設置顯示樣式;
? ? ? ? newViewController.modalPresentationStyle=UIModalPresentationStyle.FullScreen
//5、跳轉并顯示目標Controller
? ? ? ? self.presentViewController(newViewController, animated:true) {
? ? ? ? ? ? ? ? print("ok")
? ? ? ? }
}
返回之前的界面
1)通過Segue,但是要在對應的view中申明unwind方法(該方法名可以隨意,但是方法前一定要申明 @IBAction,方法的第一個參數類型必須是UIStoryBoardSegue),然后在StoryBoard中將Segue連接到對應view的Exit中的unwind方法上;
2)通過dismissViewControllerAnimated()關閉當前界面而回到上一界面;(僅適用于Modal樣式)
3)通過self.navigationController?.popToViewController(viewController: UIViewController, animated:Bool),使用的是壓棧的形式,后進先出,比如,navigationController中經過了5個View,也就是navigationControllers隊列中有5個實例對象[0、1、2、3、4],當從第四個view回退至第2個界面,直接通過pop方法,navigationController.viewControllers[1]即可。但是如之前說是壓棧的形式,所以后面的2、3、4的界面對象將消失,再次跳轉過去,會生成新的實例對象。
更新中……