IOS学习之——导航2 模态的原理和实现
2015-01-29 11:44
323 查看
什么是模态?
这是个问题,什么是模态呢?简单的说,就是你在旅游,突然老板来电话了找你解决技术问题,很急。所以你必须先搞定这个电话,然后才能接着旅游。
又或者你要看视频,网站弹出如下窗口,你必须安装软件才能接着看……
所以模态,是一种状态,你必须先解决掉这个状态,才能继续下去。
实现模态
在IOS中,模态的应用可以是点击注册页,然后注册完成回到原来页面通过storyboard获取对象
storyboardID的定义如下:
// An identifier string that uniquely identifies the view controller in the storyboard file. You set the identifier for a given view controller in Interface Builder when configuring the storyboard file. This identifier is not a property of the view controller object itself and is used only by the storyboard file to locate the view controller.
:
翻译:这个标志字符串,是故事板中试图控制器的独特的标识符。
你可以在故事板中设置这个标识符,这个标识符并不是视图控制器的属性,仅仅使用在故事版中读取视图控制器的时候。
也就是说:storyboardID用于获取和构建storyboard中的viewController对象
获取storyboard对象
// 获取storyboard 对象 UIStoryboard *mainStoryBoard=[UIStoryboard storyboardWithName:@"Main" bundle:nil]; // 利用storyBoard ID 创建uiviewcontroller 对象 UIViewController* model=[mainStoryBoard instantiateViewControllerWithIdentifier:@"ModelViewController"];
第一个函数:storyboardWithName: bundle:
试用特定的字符串,创建并且返回storyboard对象:返回的对象是下图main.storyboard
第二个函数:使用指定的标识符创建ViewController的实例,标识为:storyboardID,在属性页面设置
转换动画类型
接下来设置转换动画类型: (transition:过度)
// 过度动画
model.modalTransitionStyle=UIModalTransitionStylePartialCurl;
有四种可选的类型:
typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl NS_ENUM_***AILABLE_IOS(3_2),
};
我们来逐条解释一下:
1 cover: 包括,覆盖 Vertical:垂直的 翻译过来就是——垂直覆盖
2 flip:掷,弹出 Horizontal:水平的 翻译过来是——水平扔出,(这个好豪放……)
3 cross:交叉 dissolve:溶解 翻译过来是——交叉溶解(大约就是隐约透出来,逐渐明显)
4 partial:局部的 Curl:卷曲 翻译中文——掀起一角(自己脑补)
打开和关闭模态
1 打开模态 代码如下:[self presentViewController:model animated:YES completion:^{ NSLog(@"打开模态,就这么简单"); }];
这个函数定义在UIViewController 类里面:意思是使用一个controller 作为自己的模态,后面的参数是一个block,里面的代码伴随着函数执行而执行,有兴趣同学可以自己搜索一下
2 关闭模态 代码如下
- (IBAction)closeModel:(id)sender { [self dismissViewControllerAnimated:YES completion:^{ NSLog(@"模态结束"); }]; }
这个函数也是定义在UIViewController类里面,意思是结束自己这个Controller的模态状态,返回原来Controller
效果图:
相关代码
https://git.oschina.net/zhengaoxing/navigation欢迎转载
本文地址:http://blog.csdn.net/zhenggaoxing/article/details/43269109前一篇:
IOS学习之——导航1 概述
IOS学习系列目录:
IOS学习系列目录——不定时更新相关文章推荐
- ios 学习笔记,tabbarcontroller 实现底部导航
- iOS - 模态Model视图跳转和Push视图跳转的混合需求实现原理
- iOS底层学习-KVC使用实践以及实现原理
- IOS开发学习笔记(导航控制器,视图控制器,模态)
- IOS学习之——导航3 平铺导航1:实现基于分屏的平铺导航
- IOS-SDWebImage 底层实现原理以及面试题相关问题的学习链接
- iOS学习笔记72-Objective-C Autorelease Pool 的实现原理
- IOS学习之——定位服务1 实现原理
- OC基础:内存(进阶):retain.copy.assign的实现原理 分类: ios学习 OC 2015-06-26 17:36 58人阅读 评论(0) 收藏
- jquery 导航设计实现代码 学习jquery的朋友可以看下
- WPF学习笔记二 依赖属性实现原理及性能分析
- java集合框架学习—HashMap的实现原理
- 深入Java集合学习系列:HashSet的实现原理
- 深入Java集合学习系列:HashMap的实现原理
- java集合实现--02 --源代码学习--集合增加对象原理
- hessian简单原理及实现例子--学习
- malloc的实现原理学习(2)
- malloc的实现原理学习(1)
- 深入Java集合学习系列:LinkedHashSet的实现原理
- C#仿QQ皮肤-实现原理系列文章导航