presentViewController: 如何不覆盖原先的 viewController界面
2015-06-04 16:32
671 查看
PresentViewController 如何不遮挡住原来的viewController界面呢?
可能有时候会遇到这种需求,需要弹出一个功能比较独立的视图实现一些功能,但是却不想单纯添加一个View上去,想做成viewController的形式。那么本文就详细说明下如何实现 presentViewController并且不覆盖原先视图的解决方案。
具体源码请访问 /article/5442389.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];
}
}
效果图如下
可能有时候会遇到这种需求,需要弹出一个功能比较独立的视图实现一些功能,但是却不想单纯添加一个View上去,想做成viewController的形式。那么本文就详细说明下如何实现 presentViewController并且不覆盖原先视图的解决方案。
具体源码请访问 /article/5442389.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];
}
}
效果图如下
相关文章推荐
- Java正则表达式(转载http://www.java3z.com/cwbwebhome/article/article8/Regex/Java.Regex.Tutorial.html#reg6)
- 电子邮箱结尾总结
- iOS 动画效果
- GC机制总结
- 移植 MIUI Framework
- Sharepoint 对于是否签出文件进行编辑区别
- MVC之ActionResult
- android学习笔记(二)
- 重磅!详解阿里研究院互联网+报告
- TCP/IP-------MTU、MSS、分片
- HOJ1867 经理的烦恼
- 内存流操作
- Android学习准备
- mfc随着窗口大小调整控件大小
- python目录操作
- jQuery中json对象与json字符串互换
- Linux下 shell获取本机ip地址
- POJ 3111 K Best(最大化平均值)
- 手机页面开发 --对于不同分辨率字体的处理
- Bootstrap 斜体、文本对齐、缩略图、地址、列表等