presentViewController: 如何不覆盖原先的 viewController界面
PresentViewController 如何不遮挡住原来的viewController界面呢?
可能有时候会遇到这种需求,需要弹出一个功能比较独立的视图实现一些功能,但是却不想单纯添加一个View上去,想做成viewController的形式。那么本文就详细说明下如何实现 presentViewController并且不覆盖原先视图的解决方案。
具体源码请访问 http://www.cnblogs.com/sely-ios/p/4552134.html
UIViewController之间的底部的跳转机制,具体内容太多就不详细说明了, 不过苹果提供了自定义UIViewController之间跳转的一个Delegate,那就是UIViewControllerTransitioningDelegate,具体请参照XCode中此Protocol的介绍
那么iOS7之前就需要自定义UIViewControllerTransitioningDelegate以及UIViewControllerAnimatedTransitioning来完成我们的需求,iOS8之后苹果已经给出解决方案,只需要设置UIViewController 的 modalPresentationStyle 属性为 UIModalPresentationOverCurrentContext就可以轻松达到我们的要求。
具体如何实现呢?
这里我也参照了github上由Blanche Faur贡献的Demo https://github.com/hightech/iOS-7-Custom-ModalViewController-Transitions,很轻松就能达到想要的效果了,下面是跳转的代码
- (IBAction)presentViewController:(id)sender
{
if (self.background)
{
[self.view bringSubviewToFront:self.background];
self.background.hidden = NO;
self.background.layer.opacity = 0.3;
}
UINavigationController *navi = [self.storyboard instantiateViewControllerWithIdentifier:@"ToViewControllerNavi"];
ToViewController *toViewController = navi.viewControllers[0];
[toViewController setHandler:^(){
self.background.hidden = YES;
}];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
{
[navi setTransitioningDelegate:self.transDelegate];
navi.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:navi animated:YES completion:nil];
}
else
{
toViewController.view.backgroundColor = [UIColor clearColor];
navi.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:navi animated:YES completion:nil];
}
}
效果图如下

presentViewController: 如何不覆盖原先的 viewController界面的更多相关文章
- SqlServer 2014还原数据库时提示:无法在已有的""上还原文件,请重新发出RESTORE语句,用WITH REPLACE来覆盖原先存在的文件
场景 SQL Server 2014在还原数据库时提示: 无法在已有的""上还原文件,请重新发出RESTORE语句,用WITH REPLACE来覆盖原先存在的文件... 实现 在还 ...
- Index & Statistics ->> Rebuild Index会不会覆盖原先Index的WITH选项设置
昨天因为工作中遇到要对某个数据库的表通通启用data_compression,突然有个念头,就是如果我当初用"ALTER INDEX XXX ON YYY REBUILD WITH (DAT ...
- iOS设置某个界面强制横屏,进入就横屏
最近有一个项目,例如:A界面跳转到B界面,A界面是竖屏的,B界面进入就要横屏. 花了半天的时间在网上搜索解决方案,有些论坛的大牛也就贴两行代码,具体实现也没有,对我们这种菜鸟造成一万点真实伤害.为了避 ...
- 设置ViewController 数据源无法改变view
病情描述: viewController创建的时候勾选了xib,然后在显示的时候调用了如下语句: MTDetailDealViewController *detailController = [[MT ...
- [Android Pro] AndroidStudio IDE界面插件开发(Hello World篇)
转载请注明出处:[huachao1001的专栏:http://blog.csdn.net/huachao1001/article/details/53856916] 工欲善其事必先利其器,自打从Ecl ...
- collectionViewFlow的界面编写
#import <UIKit/UIKit.h> //这边我们会创建一个scrollView的界面,这个scrollView里面有三张图片构成,我们使用下面的枚举方式来定义这三个位置 typ ...
- cp复制文件到多个目录下及强制覆盖
工作中有遇到要把一个文件拷贝到N个文件夹下,但是cp又没有这样的命令,怎么办,这时需要编写一个脚本,首先做实验如下: [root@host1 ~]# mkdir test [root@host1 ~] ...
- iOS连续dismiss几个ViewController的方法
原文链接:http://blog.csdn.net/longshihua/article/details/51282388 presentViewController是经常会用到的展现ViewCont ...
- Cocos Creator—定制H5游戏首页loading界面
Cocos Creator从1.0版本发布到现在也有一年多了,按理说一些常见的问题网上都有解决方案,例如"如何自定义首页加载进度条界面"这种普遍需求,应该所有人都会遇到的,因此也有 ...
随机推荐
- Linux下升级python版本
转载自:http://lovebeyond.iteye.com/blog/1770476 CentOS下的Python版本一般都比较低,很多应用都需要升级python来完成.我装的centOS的默认的 ...
- GLSL实现Ambient Occlusion 【转】
http://blog.csdn.net/a3070173/archive/2008/11/04/3221181.aspx 相信使用OpenGl或DirectX3D的朋友都知道到固定功能管线在光照处理 ...
- 检测Insert、Capslock、NumLock、ScrollLock状态键的状态
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...
- hdu 4099 Revenge of Fibonacci 字典树+大数
将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...
- 统计0到n之间1的个数
问题描写叙述 给定一个十进制整数N,求出从1到N的全部整数中出现"1"的个数. 比如:N=2时 1,2出现了1个 "1" . N=12时 1,2,3,4,5,6 ...
- starling 笔记
------------------------------------------------------------------ 这里的舞台是flash原生舞台,不是starling舞台 // r ...
- 4K Block Size的Device和 Aligned IO
http://www.cnblogs.com/cenalulu/p/3587006.html 背景:最近采购了一批新的服务器,底层的存储设备的默认physical sector size从原有的 ...
- Python 计算程序运行时间
import time def start_sleep(): time.sleep(3) if __name__ == '__main__': #The start time st ...
- html笔记01:顺序和无序列表
<!DOCTYPE html> <html> <body> <li>Yellow <ul><li>Wet soil</li ...
- struts2 后台action向前端JSP传递参数的问题
后台有个方法,里面部分代码如下: System.out.print("alter:"+user.getId()); User temp=userservice.getUserByU ...