博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
视图切换总结
阅读量:4635 次
发布时间:2019-06-09

本文共 1693 字,大约阅读时间需要 5 分钟。

1、利用ModalViewController切换View

当程序中含有多个 view,需要在之间切换的时候,可以使用 UINavigationController,或者是 ModalViewController。UINabigationController 是通过向导条来切换多个 view。而如果 view 的数量比较少,且显示领域为全屏的时候,用 ModalViewController 就比较合适(比如需要用户输入信息的view,结束后自动回复到之前的view)。
ModalViewController 并不像 UINavigationController 是一个专门的类,使用 UIViewController 的 presentModalViewController 方法指定之后就是 ModalViewController 了。
调用 UIViewController 的 dismissModalViewController:Animated: 方法就可以退出
在A里面直接跳到B中     [A presentModalViewController:B animated:YES];
在B中可以通过 返回到A  [self dismissModalViewControllerAnimated:YES]
UINavigationController 的 pushViewController: animated:
UIViewController的presentModalViewController: animated:
增加 Notification
post Notification
addSubview
b bringSubviewToFront
insertSubview b atIndex 0
removeview a
IPhone中视图切换,网上常见的方法都是用viewcontrol,在viewcontrol中插入不同的视图实现,见下面的代码
[self.view insertSubview:self.mainview.view atIndex:0]; 
只要切换不同的mainview就可以实现,网上常见的方法也是如此,不过我却想用另外一种方法,就是直接操作window,
在window中切换view,实现方法如下:
[viewController.view removeFromSuperview];
[window addSubview:viewset.view];
其中viewController是当前窗口,首先从 父窗口中移除,然后调用window addSubview方法即可。
不过使用第二个方法,出现了一个问题就是原来的主窗口显示正常,但是切换到第二个窗口是,窗口被电池栏给覆盖了,显得很奇怪,目前无解。
1.首先用pushViewController切换到下一个视图的,切换回来用popViewControllerAnimated
也就是:
切换视图:[self.tabBarController.navigationController pushViewController:_appMore animated:YES];
或者[self.navigationController pushViewController:_appMore animated:YES];
切换回来的时候用:
[self.navigationController popViewControllerAnimated:YES];
2.两个view之间切换:
假设aimview是目标视图
currentview是当前视图
首先移除当前view
[currentview.view removeFromSuperview];
[self.view insertSubview:aimview.view atIndex:0]

 

 

 

转载于:https://www.cnblogs.com/jackljf/archive/2012/08/26/3589337.html

你可能感兴趣的文章
k-means k均值聚类的弱点/缺点
查看>>
《离散数学》双语专业词汇表 名词术语中英文索引
查看>>
Python初步
查看>>
【MFC】vs2013_MFC使用文件之15.mfc 按钮CBitmapButton的使用
查看>>
QGLViewer 编译安装步骤
查看>>
配置Mysql实现主从复制与读写分离
查看>>
易货Beta版本发布说明
查看>>
textbox 和textera 文本框多行后不能拉伸
查看>>
mingw + msys 上编译 ffmpeg
查看>>
使用Mule ESB与Groovy编排RESTful服务【转】很适合我们当前的架构
查看>>
适配器模式
查看>>
二叉树
查看>>
判断 iframe 是否加载完成的完美方法(转)
查看>>
一文告诉你 Event Loop 是什么?
查看>>
记录知识点或技术方案信息
查看>>
新手学html 第一节:html简介
查看>>
【C】strcpy()需谨慎使用;
查看>>
docker安装nginx容器小记
查看>>
SUSE11 搭建iscsi target 配置
查看>>
5.3linux下C语言socket网络编程简例
查看>>