/*
《 Swift -->>UINavigationController 的使用和其详细属性的设置等详细解说和控制栈的解说》
*/
// Created by 周双建 on 15/12/5.
// copyright © 2015年 周双建. All rights reserved.
//
import UIKit
class VIEwController: UIVIEwController {
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
//首先给 控制器的背景设置个颜色
self.vIEw.backgroundcolor = UIcolor.redcolor()
//设置视图控制器的标题(其实导航栏上显示的标题是视图控制器的)
self.Title = "成功QQ吧"
/*******************************属性介绍****************************/
//更改导航控制器的背景颜色
self.navigationController?.navigationbar.barTintcolor = UIcolor.whitecolor()
//设置其背景为图片
/*
设置导航栏的背景图片,需要主意图片的尺寸
1、 640 * 88 图片的命名 [email protected]
2、其他
*/
// 首先清除上面更改的导航栏的背景颜色
self.navigationController?.navigationbar.barTintcolor = UIcolor.clearcolor()
// 设置导航栏的背景图片
self.navigationController?.navigationbar.setBackgroundImage(UIImage(named: "25E823C0-E342-4FC5-8654-3EDDF85873D1"),forbarMetrics: UIbarMetrics.Default)
/*
运行的效果是,包含上面的状态栏 ,切图片不会自适应导航栏的大小,文字是黑色
// 横屏下的导航栏的背景图片设置
.top,barMetrics: UIbarMetrics.Default)
/******************************************************************/
//导航栏的透明的处理
/*
如果使用导航控制器,来管理视图,默认情况下,视图的位置坐标原点是在手机屏幕的左上角。 导航栏是出于半透明状态
*/
//设置导航栏 为不透明
self.navigationController?.navigationbar.translucent = false
/*
这时候,视图的圆点坐标,就从导航栏的左下方开始了
/******************************************************************/
//如果不想使用,系统的导航栏,我们可以将其隐藏,但是:视图的坐标,有从手机屏幕的左上角开始了
self.navigationController?.navigationbarHIDden = true
//做视图控制器间的切换 使用push 方法
//我们首先,创建一个可以点击的按钮,让它作为跳转的出发
let VCBtn_ZSJ = UIbutton(type: UIbuttonType.Custom) as UIbutton
VCBtn_ZSJ.frame = CGRectMake(40, 100,self.vIEw.frame.size.wIDth-80,40)
VCBtn_ZSJ.setTitle("触发跳转按钮",forState: UIControlState.normal)
VCBtn_ZSJ.addTarget(self,action: "BtnClick",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(VCBtn_ZSJ)
@H_748_403@ @H_715_404@跳转方法: @H_748_403@
/******************************************************************/
//跳转的出发方法的实现
func BtnClick(){
// 首先将视图导航栏,显示
self.navigationController?.navigationbarHIDden = false
let TVC = TwoVIEwController()
//进行视图的push 跳转
self.navigationController?.pushVIEwController(TVC,animated: true)
/*
就是界面 从右向左滑动的效果 animated 为 true 同时,第二个控制器的导航栏的左侧,有个返回按钮,点击即可返回上一个视图控制器。
*/
// 现在,我们不想使用系统的返回按钮,我们可以自己定义个返回按钮,这就要到第二个控制器里面,谈论了。go T
}
@H_748_403@ @H_715_404@要实现,一个返回按钮,在跳转后的界面: @H_748_403@import UIKit
class TwoVIEwController: UIVIEwController {
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
//设置视图控制器的背景色
self.vIEw.backgroundcolor = UIcolor.purplecolor()
// 我们要自定一个返回按钮,进行触发返回事件
let Back_ZSJ = UIbutton(type: UIbuttonType.Custom) as UIbutton
Back_ZSJ.frame = CGRectMake(20,self.vIEw.frame.size.wIDth-40,40)
Back_ZSJ.setTitle("返回上一个控制器",forState: UIControlState.normal)
Back_ZSJ.addTarget(self,action: "Back",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(Back_ZSJ)
@H_748_403@@H_715_404@其跳转方法: @H_748_403@ @H_715_404@
/******************************************************************/
//在这里实现,返回的事件处理
func Back(){
//@H_502_640@实现返回
self.navigationController?.popVIEwControllerAnimated(true)
}
@H_748_403@下面我们要讨论视图控制器栈的访问
/*****************************************************************/
//下面我们要讨论视图控制器栈的访问
//第一我们在要创建一个视图控制器 3
//在创建一个按钮,实现界面的跳转
let TVC_Btn = UIbutton(type: UIbuttonType.Custom) as UIbutton
TVC_Btn.setTitle("跳转到第三个视图控制器",forState: UIControlState.normal)
TVC_Btn.frame = CGRectMake(20, 200,40)
TVC_Btn.addTarget(self,action: "Btn",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(TVC_Btn)
// Do any additional setup after loading the vIEw.
}
@H_748_403@ 其点击方法: @H_748_403@/******************************************************************/
//在这里实现界面的跳转
func Btn(){
//获取跳转目标控制的对象
let T_ZSJ = ThreeVIEwController()
self.navigationController?.pushVIEwController(T_ZSJ,animated: true)
//
// ThreeVIEwController.swift
// Swift_007
// Created by 周双建 on 15/12/5.
// copyright © 2015年 周双建. All rights reserved.
//
import UIKit
class ThreeVIEwController: UIVIEwController {
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
//给视图控制器设置颜色
self.vIEw.backgroundcolor = UIcolor.bluecolor()
//打印视图控制器导航控制器的视图
print(self.navigationController?.vIEwControllers)
/*
打印结果:
Optional([<Swift_007.VIEwController: 0x7fa302474ac0>,<Swift_007.TwoVIEwController: 0x7fa3024926f0>,<Swift_007.ThreeVIEwController: 0x7fa302536a40>])
是按照入栈 ,进行输出
*/
/*************************************************************/
//在这里,我们要实现视图控制器的多级跳转
//我们要创建三个按钮,来触发这个事件
/*******************************************/
// 返回上一个界面
let TVC_Btn = UIbutton(type: UIbuttonType.Custom) as UIbutton
TVC_Btn.setTitle("UIControlState.normal)
TVC_Btn.frame = CGRectMake(20,40)
TVC_Btn.addTarget(self,action: "BackBtn",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(TVC_Btn)
// 返回到跟控制器
let TVCR_Btn = UIbutton(type: UIbuttonType.Custom) as UIbutton
TVCR_Btn.setTitle("跳转到主控制器",forState: UIControlState.normal)
TVCR_Btn.frame = CGRectMake(20,40)
TVCR_Btn.addTarget(self,action: "BackRootBtn",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(TVCR_Btn)
// 跳转到指定的控制器
let TVCRZ_Btn = UIbutton(type: UIbuttonType.Custom) as UIbutton
TVCRZ_Btn.setTitle("跳转到自定义的主控制器",forState: UIControlState.normal)
TVCRZ_Btn.frame = CGRectMake(20, 300,40)
TVCRZ_Btn.addTarget(self,action: "BackRootautoBtn",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(TVCRZ_Btn)
// Do any additional setup after loading the vIEw.
}
/***************************************************************/
//返回,上一个界面的方法
func BackBtn(){
self.navigationController?.popVIEwControllerAnimated(true)
}
// 返回到根视图控制器
func BackRootBtn(){
self.navigationController?.popToRootVIEwControllerAnimated(true)
}
//跳转指定的界面
func BackRootautoBtn(){
// 首先,我们要通过导航栈 ,来获取要跳转控制器的地址
let VC = (self.navigationController?.vIEwControllers[1])! as UIVIEwController
self.navigationController?.popToVIEwController(VC,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.
}
*/
}
@H_748_403@/****************************************************************/
// 设置 导航栏的右侧按钮
let Itms = UIbarbuttonItem(Title: "按钮右",style: UIbarbuttonItemStyle.Plain,target: self,action: "Btn_Right")
self.navigationItem.rightbarbuttonItem = Itms
// 设置左按钮
// 使用系统图标
/*
public enum UIbarbuttonSystemItem : Int {
case Done 系统图片显示 Done 做
case Cancel Cancel 取消
case Edit Edit 编辑
case Save Save 保存
case Add + 添加
case FlexibleSpace 不可使用
case Fixedspace 不可使用
case Compose 编辑
case Reply 类似与返回按钮
case Action 分享按钮
case Organize 文件
case Bookmarks 书签
case Search 收索镜
case Refresh 重载
case Stop 停止 X
case Camera 相机
case Trash 垃圾筐
case Play 播放图
case Pause 停止 ||
case Rewind 快退按钮
case FastForward 快进按钮
@available(iOS 3.0,*)
case Undo Undo
case Redo Redo
@available(iOS 4.0,0)"> case PageCurl 无显示
}
*/
let Itms1 = UIbarbuttonItem(barbuttonSystemItem: UIbarbuttonSystemItem.PageCurl,170)"> self.navigationItem.leftbarbuttonItem = Itms1
/****************************************************************/
//设置新出按钮的,返回键上的文字
let TTCL = UIbarbuttonItem(Title: "笑话",action: "Plain")
self.navigationItem.backbarbuttonItem = TTCL
// Do any additional setup after loading the vIEw,typically from a nib.
}
//跳转的出发方法的实现
func BtnClick(){
// 首先将视图导航栏,显示
self.navigationController?.navigationbarHIDden = false
let TVC = TwoVIEwController()
//进行视图的push 跳转
self.navigationController?.pushVIEwController(TVC,animated: true)
/*
就是界面 从右向左滑动的效果 animated 为 true 同时,第二个控制器的导航栏的左侧,有个返回按钮,点击即可返回上一个视图控制器。
*/
// 现在,我们不想使用系统的返回按钮,我们可以自己定义个返回按钮,这就要到第二个控制器里面,谈论了。go T
}
//右侧,按钮的点击事件处理
func Btn_Right(){
print("我是右按钮")
}
overrIDe func dIDReceiveMemoryWarning() {
super.dIDReceiveMemoryWarning()
// dispose of any resources that can be recreated.
}
}
总结以上是内存溢出为你收集整理的《 Swift -->>UINavigationController 的使用和其详细属性的设置等详细解说和控制栈的解说》全部内容,希望文章能够帮你解决《 Swift -->>UINavigationController 的使用和其详细属性的设置等详细解说和控制栈的解说》所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)