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. 牛客假日团队赛1 J.分组

    链接: https://ac.nowcoder.com/acm/contest/918/J 题意: 在Farmer John最喜欢的节日里,他想要给他的朋友们赠送一些礼物.由于他并不擅长包装礼物,他想 ...

  2. springBoot实现socketio

    https://github.com/mrniko/netty-socketio-demo https://github.com/mrniko/netty-socketio

  3. B. Tell Your World

    http://codeforces.com/contest/849/problem/B 题目是给出n个点,要求把这n个点分成两组,每组都是一条直线.而且这两组不能为空,还要是平行的. 思路: 对于前3 ...

  4. Unity 切换场景的时候让某个游戏对象不消失

    DontDestroyOnLoad(要操作的GanmeObject); 放在Start方法里就行

  5. HTML5 应用缓存和常规的 HTML 浏览器缓存有何差别?

    HTML5 的应用缓存最关键的就是支持离线应用,可获取少数或者全部网站内容,包括 HTML.CSS.图像和 JavaScript 脚本并存在本地.该特性加速了网站的性能,可通过如下方式实现: < ...

  6. 并发包阻塞队列之ArrayBlockingQueue

    并发包阻塞队列之ArrayBlockingQueue   jdk1.7.0_79  上一节中对并发包中的非阻塞队列ConcurrentLinkedQueue的入队.出队做了一个简要的分析,本文将对并发 ...

  7. Android入门:封装一个HTTP请求的辅助类

    前面的文章中,我们曾经实现了一个HTTP的GET 和 POST 请求: 此处我封装了一个HTTP的get和post的辅助类,能够更好的使用: 类名:HttpRequestUtil 提供了如下功能: ( ...

  8. ZR18提高5解题报告

    不想说啥了,比赛期间智商全程下线 A 设$f[i][j]$表示前$i$个位置,前缀和为$j$的方案数,转移的时候该位置放了什么,以及该位置之前的和是多少. 发现第二维可以前缀和优化. 不用管代码里的f ...

  9. tas5717/5719功放问题点总结

    问题一 AMP output channel invert problem and modification 原因:如果硬件设计时,耳机或者喇叭的输出通道反了,就要对其进行左右对换. 对策:如果通道反 ...

  10. python3基础09(装饰器的使用)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import time #方式1class People: def __init__(self, name, a ...