導(dǎo)航欄腥刹,頁面跳轉(zhuǎn)

導(dǎo)航欄

//ViewController.swift

//UINavigationController

//

//Created by lanou on 16/11/2.

//Copyright (c) 2016年lanou. All rights reserved.

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

//每一個被導(dǎo)航視圖控制器所管理的視圖控制器都有一個navigationItem(這里包含了左按鈕怠李,右按鈕草戈,中間標(biāo)題台颠,中間視圖)

//設(shè)置導(dǎo)航欄標(biāo)題

navigationItem.title = "Setting"

let leftBarBtn = UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: "leftBtnAction")

//設(shè)置導(dǎo)航欄左按鈕(UIBarButtonItem)

navigationItem.leftBarButtonItem = leftBarBtn

let rightBarBtn = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "rightBtnAction")

navigationItem.rightBarButtonItem = rightBarBtn

//? ? ? ? navigationItem.leftBarButtonItems = [leftBarBtn,rightBarBtn]

//? ? ? ? navigationItem.rightBarButtonItems = [leftBarBtn,rightBarBtn]

//設(shè)置中間視圖

let segment = UISegmentedControl(items: ["已接來電","未接來電"])

segment.frame = CGRectMake(0, 0, 100, 30)

segment.selectedSegmentIndex = 0

navigationItem.titleView = segment

//導(dǎo)航欄(UINavigationBar)

//在本類中(視圖控制器)訪問navigationController就是獲取的到本視圖控制器所在的導(dǎo)航視圖控制器

//設(shè)置導(dǎo)航欄是否隱藏

navigationController?.navigationBarHidden = false

//設(shè)置導(dǎo)航欄的樣式

navigationController?.navigationBar.backgroundColor = UIColor.cyanColor()

//設(shè)置導(dǎo)航欄本身的顏色

navigationController?.navigationBar.barTintColor = UIColor.yellowColor()

//設(shè)置導(dǎo)航欄元素的顏色

navigationController?.navigationBar.tintColor = UIColor.redColor()

//導(dǎo)航欄半透明效果

navigationController?.navigationBar.translucent = true

let myView = UIView(frame: CGRectMake(0, 0, 60, 60))

myView.backgroundColor = UIColor.blueColor()

view.addSubview(myView)

}

func leftBtnAction(){

print("click left Btn")

}

//跳轉(zhuǎn)到第二個控制器的頁面

func rightBtnAction(){

//(1)創(chuàng)建第二個控制器

let secondVC = secondViewController()

//(2)使用當(dāng)前控制器所在的導(dǎo)航視圖控制器跳轉(zhuǎn)到第二個控制器,pushViewController可以進入到下一個頁面

navigationController?.pushViewController(secondVC, animated: true)

print("click right Btn")

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

//secondViewController.swift

//UINavigationController

//

//Created by lanou on 16/11/3.

//Copyright (c) 2016年lanou. All rights reserved.

import UIKit

class secondViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

navigationItem.title = "seconrVC"

//設(shè)置顏色

view.backgroundColor = UIColor.whiteColor()

let leftBarBtn = UIBarButtonItem(title: "back", style: UIBarButtonItemStyle.Plain, target: self, action: "backAction:")

navigationItem.leftBarButtonItem = leftBarBtn

}

func backAction(btn:UIBarButtonItem){

println("返回")

//將secondVC出棧,popViewControllerAnimated:將當(dāng)前的顯示在棧頂?shù)目刂破鞒鰲?/p>

navigationController?.popViewControllerAnimated(true)

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

}

}


//? FifthViewController.swift

//? UINavigationController

//

//? Created by SZT on 2016/11/3.

//? Copyright ? 2016年 SZT. All rights reserved.

//

import UIKit

class FifthViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

view.backgroundColor = UIColor.whiteColor()

navigationItem.title = "FifthVC"

let leftBtn = UIBarButtonItem(title: "backToRoot", style: UIBarButtonItemStyle.Plain, target: self, action: "popToRootViewController")

navigationItem.leftBarButtonItem = leftBtn

let btn = UIButton(frame: CGRectMake(100,130,80,45))

btn.setTitle("模態(tài)顯示", forState: .Normal)

btn.backgroundColor = UIColor.cyanColor()

btn.addTarget(self, action: "presentToSix", forControlEvents: .TouchUpInside)

view.addSubview(btn)

}

//點擊按鈕模態(tài)顯示第六個視圖控制器

func presentToSix(){

//創(chuàng)建第六個視圖控制器

let sixthVC = SixthViewController()

//模態(tài)顯示定嗓,跟導(dǎo)航視圖控制器沒關(guān)系

//參數(shù)completion:模態(tài)顯示完成之后要執(zhí)行的閉包

presentViewController(sixthVC, animated: true) { () -> Void in

//模態(tài)顯示動作完成要執(zhí)行的代碼

print("模態(tài)動作已完成")

}

}

func popToRootViewController(){

//(1)popToRootViewControllerAnimated:回到根視圖控制器

//? ? ? ? navigationController?.popToRootViewControllerAnimated(true)

//? ? ? ? (2)

//先獲取到棧里所有的視圖控制器

let viewControllers = navigationController?.viewControllers

//獲取根視圖控制器(因為根視圖控制器是最先入棧枯怖,所以在第0個下標(biāo))

let rootVC:UIViewController = viewControllers![0]

//導(dǎo)航視圖控制器返回到指定的視圖控制器

navigationController?.popToViewController(rootVC, animated: true)

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

//SixthViewController.swift

//UINavigationController

//

//Created by SZT on 2016/11/3.

//Copyright ? 2016年SZT. All rights reserved.

import UIKit

class SixthViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

view.backgroundColor = UIColor.grayColor()

let modelBtn = UIButton(frame: CGRectMake(80,150,100,45))

modelBtn.setTitle("模態(tài)消失", forState: .Normal)

modelBtn.backgroundColor = UIColor.blueColor()

modelBtn.addTarget(self, action: "dismissViewcontroller", forControlEvents: .TouchUpInside)

view.addSubview(modelBtn)

}

func dismissViewcontroller(){

//? ? (1)第一種方式:模態(tài)過程不可定制化? dismissViewcontroller()

//(2)第二種方式:模態(tài)消失過程可定制化(需不需要動畫注整,模態(tài)結(jié)束后執(zhí)行代碼段)

dismissViewControllerAnimated(true) { () -> Void in

print("模態(tài)消失動作已結(jié)束")

}

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

/*

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

// Get the new view controller using segue.destinationViewController.

// Pass the selected object to the new view controller.

}

*/

}

/*

}

*/

}

/*

頁面跳轉(zhuǎn)的方式

1.模態(tài)顯示

//創(chuàng)建第六個視圖控制器

letsixthVC = SixthViewController()

//模態(tài)顯示,跟導(dǎo)航視圖控制器沒關(guān)系

//參數(shù)completion:模態(tài)顯示完成之后要執(zhí)行的閉包

presentViewController(sixthVC, animated:true) { () ->Voidin

//模態(tài)顯示動作完成要執(zhí)行的代碼

print("模態(tài)動作已完成")

}

2.push

*/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市肿轨,隨后出現(xiàn)的幾起案子寿冕,更是在濱河造成了極大的恐慌,老刑警劉巖萝招,帶你破解...
    沈念sama閱讀 218,204評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蚂斤,死亡現(xiàn)場離奇詭異,居然都是意外死亡槐沼,警方通過查閱死者的電腦和手機曙蒸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來岗钩,“玉大人纽窟,你說我怎么就攤上這事〖嫦牛” “怎么了臂港?”我有些...
    開封第一講書人閱讀 164,548評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長视搏。 經(jīng)常有香客問我审孽,道長,這世上最難降的妖魔是什么浑娜? 我笑而不...
    開封第一講書人閱讀 58,657評論 1 293
  • 正文 為了忘掉前任佑力,我火速辦了婚禮,結(jié)果婚禮上筋遭,老公的妹妹穿的比我還像新娘打颤。我一直安慰自己,他們只是感情好漓滔,可當(dāng)我...
    茶點故事閱讀 67,689評論 6 392
  • 文/花漫 我一把揭開白布编饺。 她就那樣靜靜地躺著,像睡著了一般响驴。 火紅的嫁衣襯著肌膚如雪透且。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,554評論 1 305
  • 那天踏施,我揣著相機與錄音石蔗,去河邊找鬼。 笑死畅形,一個胖子當(dāng)著我的面吹牛养距,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播日熬,決...
    沈念sama閱讀 40,302評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼棍厌,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起耘纱,我...
    開封第一講書人閱讀 39,216評論 0 276
  • 序言:老撾萬榮一對情侶失蹤敬肚,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后束析,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體艳馒,經(jīng)...
    沈念sama閱讀 45,661評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,851評論 3 336
  • 正文 我和宋清朗相戀三年员寇,在試婚紗的時候發(fā)現(xiàn)自己被綠了弄慰。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,977評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡蝶锋,死狀恐怖陆爽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情扳缕,我是刑警寧澤慌闭,帶...
    沈念sama閱讀 35,697評論 5 347
  • 正文 年R本政府宣布,位于F島的核電站躯舔,受9級特大地震影響驴剔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜粥庄,卻給世界環(huán)境...
    茶點故事閱讀 41,306評論 3 330
  • 文/蒙蒙 一仔拟、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧飒赃,春花似錦、人聲如沸科侈。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽臀栈。三九已至蔫慧,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間权薯,已是汗流浹背姑躲。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留盟蚣,地道東北人黍析。 一個月前我還...
    沈念sama閱讀 48,138評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像屎开,于是被迫代替她去往敵國和親阐枣。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,927評論 2 355

推薦閱讀更多精彩內(nèi)容