import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//设置导航栏的标题
//每一个被导航视图控制器所管理的视图控制器都有一个navigationItem(这里面包含了类左按钮,右按钮,中间标题,中间视图)
navigationItem.title = "Setting"
//设置导航栏左按钮
let letfBarBtn = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Search, target: self, action: "letfBtnAction")
let rightBarBtn = UIBarButtonItem(title: "next", style: UIBarButtonItemStyle.Plain, target: self, action: "rightBtnAction")

// let rightBarBtn = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Rewind, target: self, action: "rightBtnAction")

navigationItem.leftBarButtonItem = letfBarBtn

navigationItem.rightBarButtonItem = rightBarBtn

// navigationItem.leftBarButtonItems = [letfBarBtn,rightBarBtn]

// navigationItem.rightBarButtonItems = [rightBarBtn,letfBarBtn]

//设置中间视图

let segment = UISegmentedControl(items: ["已接来电","未接来电"])

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

segment.selectedSegmentIndex = 0

navigationItem.titleView = segment

    //导航栏(UINavigationBar)
//在本类中(视图控制器)访问navigationController就是获取到本视图控制器所在的导航视图控制器
//设置导航栏是否隐藏
navigationController?.navigationBarHidden = false //设置导航栏样式
navigationController?.navigationBar.barStyle = UIBarStyle.Default
//背景颜色
navigationController?.navigationBar.backgroundColor = UIColor.cyanColor()
//导航栏本身的颜色
navigationController?.navigationBar.barTintColor = UIColor.yellowColor()
//导航栏元素颜色(左按钮 右按钮 中间标题........)
navigationController?.navigationBar.tintColor = UIColor.redColor()
//导航栏半透明效果
navigationController?.navigationBar.translucent = true let myView = UIView(frame: CGRectMake(0, 0, 150, 150))
myView.backgroundColor = UIColor.blueColor()
view.addSubview(myView)
}
func letfBtnAction(){
print("dfsfdsf")
}
//跳转第二个控制器页面
func rightBtnAction(){
//(1)创建第二个控制器
let secondVC = SecondViewController()
//(2)使用当前控制所在的导航视图控制器跳转到第二个控制器pushViewController(进入到下一个页面)
navigationController?.pushViewController(secondVC, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

import UIKit

class SecondViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
//设置页面颜色为白色
view.backgroundColor = UIColor.whiteColor()
navigationItem.title = "SecondVC" let leftBarBtn = UIBarButtonItem(title: "back", style: UIBarButtonItemStyle.Plain, target: self, action: "backAction:")
let rightBarBtn = UIBarButtonItem(title: "next", style: UIBarButtonItemStyle.Plain, target: self, action: "rightBtnAction")
navigationItem.leftBarButtonItem = leftBarBtn
navigationItem.rightBarButtonItem = rightBarBtn // Do any additional setup after loading the view.
}
func backAction(btn:UIBarButtonItem){
print("111")
//将secondVC出輚
//(回到上一个页面)将SecondVC出輚popViewControllerAnimated:将当前显示在栈顶的控制器出輚
// navigationController?.popViewControllerAnimated(true)
//先获取到棧里所有的视图控制器
let viewControllers = navigationController?.viewControllers
//获取根视图控制器(因为根视图控制器是最先入栈,所以在第0个下标)
let rootVC: AnyObject = viewControllers![0]
//导航视图控制器返回到指定的视图控制器
navigationController?.popToViewController(rootVC as! UIViewController, animated: true)
}
func rightBtnAction(){
let ThirdVC = ThirdViewController()
navigationController?.pushViewController(ThirdVC, animated: true)
}
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.
}
*/

}

import UIKit

class ThirdViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let myBtn = UIButton(frame: CGRectMake(100, 130, 100, 45))
myBtn.setTitle("模态显示", forState: UIControlState.Normal)
myBtn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
myBtn.backgroundColor = UIColor.redColor()
myBtn.addTarget(self, action: "presentToFifes", forControlEvents: UIControlEvents.TouchUpInside)
view.addSubview(myBtn)
let leftBarBtn = UIBarButtonItem(title: "back", style: UIBarButtonItemStyle.Plain, target: self, action: "backAction:")
// Do any additional setup after loading the view.
}
func backAction(btn:UIBarButtonItem){
print("222")
navigationController?.popViewControllerAnimated(true)
} func presentToFifes(){
print("模态")
let foursVC = FoursViewController()
//模态显示,跟导航视图控制器没关系
//参数completion:模态显示完成后要执行的闭包
presentViewController(foursVC, animated: true) { () -> Void in } }
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.
}
*/

import UIKit

class FoursViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.cyanColor()
let modelBtn = UIButton(frame: CGRectMake(80, 150, 80, 45))
modelBtn.setTitle("模态消失", forState: UIControlState.Normal)
modelBtn.backgroundColor = UIColor.whiteColor()
modelBtn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
modelBtn.addTarget(self, action: "dismissViewController", forControlEvents: UIControlEvents.TouchUpInside)
view.addSubview(modelBtn)
// Do any additional setup after loading the view.
}
func dismissViewController(){
//1.第一种方式:dismissViewController()模态消失过程不可定制化
//2.第二种方式:模态消失过程可定制化(需不需要动画,模态结束后执行代码段 )
dismissViewControllerAnimated(true, completion: { () -> Void in
print("模态消失动作已经结束")
})
}
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.
}
*/

}

ios 导航视图控制器 跳转的更多相关文章

  1. UI 07 _ 导航视图控制器 与 属性传值

    首先, 先创建三个VC. 完毕点击按钮, 进入下一页, 并可以返回. 要先把导航视图控制器创建出来. 在AppDelegate.m 文件里代码例如以下: #import "AppDelega ...

  2. UI - 视图控制器跳转另一个视图控制器特效总结

    1. 从一个视图控制器跳转另一个视图控制器的方式是可以进行设置的 CATransition *animation = [[CATransition alloc]init]; animation.dur ...

  3. [转]iOS之浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法

    参考:http://www.mamicode.com/info-detail-469709.html 一.最普通的视图控制器UIViewContoller 一个普通的视图控制器一般只有模态跳转的功能( ...

  4. iOS之浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法

    .最普通的视图控制器UIViewContoller 一个普通的视图控制器一般只有模态跳转的功能(ipad我不了解除外,这里只说iPhone),这个方法是所有视图控制器对象都可以用的,而实现这种功能,有 ...

  5. iOS-UIViewController视图控制器跳转界面的几种常用方法

    一.最普通的视图控制器UIViewContoller 一个普通的视图控制器一般只有模态跳转的功能(ipad我不了解除外,这里只说iPhone),这个方法是所有视图控制器对象都可以用的,而实现这种功能, ...

  6. Snail—UI学习之导航视图控制器UINavigationController(系统)

    背景 有一个根视图控制器 然后跳转到第一个界面  第一个界面能够返回到根视图 也能够跳转到第二个视图 第二个视图能够直接返回到根视图 新建三个ViewController    RootViewCon ...

  7. iOS UI-(多)视图控制器的生命周期、加载方法和模态视图方法以及屌丝方法

    #import "ViewController.h" #import "SecondViewController.h" @interface ViewContr ...

  8. iOS 在视图控制器里面判断 应用程序的前台 后台切换 UIViewController

    1.时机  用户点击home 键  应用退到后台 再次点击进入前台  在UIViewController里面 控制器如何获取相关的事件? 2.需求 (1)NSTimer   在应用程序进入后台 10秒 ...

  9. 玩转iOS开发 - 视图控制器生命周期

    视图控制器生命周期

随机推荐

  1. 上传图片时实时显示功能使用uploadPreview.js

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>添加商品分类</tit ...

  2. input和button不同高 和 rem

    rem的使用 浏览器中默认的字体大小是 16px,此时为 100%.当我们在使用 rem 的时候,常常给 html设置为 html{font-size:62.5;},这样的好处是 1rem 刚好为 1 ...

  3. myeclipse非正常关闭处理办法

    myeclipse正常或非正常关闭后,再次运行,不显示启动时的logo和读条,进入主页面后程序基本就卡死,无法正常运行,解决办法. 方法一:修改工作空间在刚启动Myeclipse的时候会有一个选择工作 ...

  4. Hive 基本语法操练(四):Hive 复合类型

    hive语法中主要提供了以下复合数据类型: 1)Structs: structs内部的数据可以通过DOT(.)来存取.例如,表中一列c的类型为STRUCT{a INT; b INT},我们可以通过c. ...

  5. MapReduce实战:邮箱统计及多输出格式实现

    紧接着上一篇博文我们学习了MapReduce得到输出格式之后,在这篇博文里,我们将通过一个实战小项目来熟悉一下MultipleOutputs(多输出)格式的用法. 项目需求: 假如这里有一份邮箱数据文 ...

  6. KindEditor编辑器使用

    KindEditor使用 1)kindeditor默认模式调用 <link rel="stylesheet" href="./KindEditor/themes/d ...

  7. C 碎片七 指针

    一.地址和指针 程序在编译过程中,系统会根据变量类型分配一定长度的内存单元.内存区中的每个字节都有一个编号,该内存单元的初始编号就是变量的"地址/指针",该内存单元的长度就是变量的 ...

  8. EasyUI Combobox 的 onChange,onSelect,onClick 事件

    EasyUI 中 Combobox 选项发生改变时会触发 onChange,onSelect,onClick,3 个事件.最近要做一个级联的 Combo 菜单,类似于选择地址时让用户填写省,市,区的菜 ...

  9. 【精华】9张思维导图带你学习Javascript

    转自:ChokCoco(http://www.cnblogs.com/coco1s/p/3953653.html) 学习的道路就是要不断的总结归纳,好记性不如烂笔头,so,下面将po出8张javasc ...

  10. 关于Mybatis的pagehelper使用遇到的坑

    参考博客: https://blog.csdn.net/wzyxdwll/article/details/66473466 下面给出pagehelp使用的配置, 在springmvc中的配置: 下面是 ...