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. 08-图8 How Long Does It Take (25 分

    Given the relations of all the activities of a project, you are supposed to find the earliest comple ...

  2. 非局部均值去噪(NL-means)

    非局部均值(NL-means)是近年来提出的一项新型的去噪技术.该方法充分利用了图像中的冗余信息,在去噪的同时能最大程度地保持图像的细节特征.基本思想是:当前像素的估计值由图像中与它具有相似邻域结构的 ...

  3. jquery——整屏滚动

    从这里下载了滚轮事件插件:https://github.com/jquery/jquery-mousewheel 函数节流:js中有些事件的触发频率非常高,在短时间内多次触发执行绑定函数,比如mous ...

  4. 二维hash

    题目描述 给出一个n * m的矩阵.让你从中发现一个最大的正方形.使得这样子的正方形在矩阵中出现了至少两次.输出最大正方形的边长. 输入描述: 第一行两个整数n, m代表矩阵的长和宽: 接下来n行,每 ...

  5. Python 类总结

    Python可以继承多个父类,多重继承. 类支持多个对象的产生,命名空间的继承,运算符重载1).类产生多个实例对象Python OOP模型中的两种对象:类对象和实例对象.类对象提供默认的行为,是实例对 ...

  6. (转)Linux硬链接、软链接及inode详解

    inode 文件储存在硬盘上,硬盘的最小存储单位叫做“扇区”(Sector).每个扇区储存512字节(相当于0.5KB). 操作系统读取硬盘的时候,不会一个个扇区地读取,这样效率太低,而是一次性连续读 ...

  7. C#常用控件的属性以及方法(转载)

    -----以前看别人的,保存了下来,但是忘了源处,望见谅. C#常用控件属性及方法介绍 目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文本框)控件 4.RichText ...

  8. launchctl

    Launchctl 系统启动时, 系统会以root用户的身份扫描/System/Library/LaunchDaemons和/Library/LaunchDaemons目录, 如果文件中有Disabl ...

  9. .net core mvc项目部署nginx报错一直显示404错误

    遇到一个奇怪的问题,.net core mvc 项目部署到nginx上面,系统是linux,controller明明抛出500错误,但页面一直显示是404. 解决如下: 1.修改Startup.cs, ...

  10. python_3 :用python微信跳一跳

    [学习使用他人代码] 2018年01月21日 19:29:02 独行侠的守望 阅读数:319更多 个人分类: Python 编辑 版权声明:本文为博主原创文章,转载请注明文章链接. https://b ...