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. ie 9 position:fixed 无效的两种情况

    第一种情况: 运行发现在Google Chrome,FireFox都可以的,但是在IE9就不行了很是郁闷,因为IE6以上的版本都是支持fixed的属性的:上网上找了好久没找到,因为不知道关键字该怎么搜 ...

  2. ubuntu16.0.4下修改MySQL的data目录之mysqld启动报错

    由于需要更换MySQL的data目录,更改完成后启动报错如下: apparmor="DENIED" operation="mknod" profile=&quo ...

  3. P1977 出租车拼车(DP)

    题目背景 话说小 x 有一次去参加比赛,虽然学校离比赛地点不太远,但小 x 还是想坐 出租车去.大学城的出租车总是比较另类,有“拼车”一说,也就是说,你一个人 坐车去,还是一堆人一起,总共需要支付的钱 ...

  4. Linux--1 初识

    一.服务器核心知识 1.电脑和电脑的硬件组成 现在的人们几乎无时无刻不在使用着电脑!不管是桌上型电脑(桌机).笔记型电脑(笔电).平板电脑,还是智慧型手机等等,这些东西都算是电脑.虽然接触这么多,但是 ...

  5. 使用open live writer客户端写博客(亲测有效)

    博客都开了这么久了,才开始将资料上传,但是每次都要登录网页确实很麻烦,所以就用open live writer,使用起来真的是挺方便的,所以将我在安装配置时,发现的问题汇总起来以便日后再次碰到忘记怎么 ...

  6. jquery——幻灯片(只动一屏)

    制作天天生鲜的幻灯片部分 贴了全部代码: main.html: <!DOCTYPE html> <html lang="en"> <head> ...

  7. Spring学习(五)事务管理

    Spring 事务管理: 一.事务概念: 1.什么是事务? 事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性,一个事务中的一系列的 ...

  8. Gym 101055A 计算几何,暴力

    http://codeforces.com/gym/101055/problem/A 题目:给定一些三维空间的点,要你找一个平面,能覆盖尽量多的点,只要求输出点数即可.n<=50 因为数据量小, ...

  9. Spring事务管理的注解方式

    使用注解实现Spring的声明式事务管理,更加简单! 步骤: 1) 必须引入Aop相关的jar文件 2) bean.xml中指定注解方式实现声明式事务管理以及应用的事务管理器类 3)在需要添加事务控制 ...

  10. CentOS6.5 环境安装配置

    一.GO环境配置 1.运行命令进入/usr/local/src目录:cd /usr/local/src 2.下载安装包:运行wget --no-check-certificate https://st ...