目前Apple推荐的场景转换的方法有以下几个:

一般的跳转方法:

presentViewController

Discussion

In a horizontally compact environment, the presented view is always full screen. In a horizontally regular environment, the presentation depends on the value in the modalPresentationStyle property.

This method sets the presentedViewController property to the specified view controller, resizes that view controller'€™s view based on the presentation style and then adds the view to the view hierarchy. The view is animated onscreen according to the transition style specified in the modalTransitionStyle property of the presented view controller.

The completion handler is called after the viewDidAppear: method is called on the presented view controller.

要点:传统的模态跳转方法

dismissViewControllerAnimated

Discussion

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

If you want to retain a reference to the receiver'€™s presented view controller, get the value in the presentedViewController property before calling this method.

The completion handler is called after the viewDidDisappear: method is called on the presented view controller.

要点:与presentViewController搭配使用

使用导航栏/Split View时使用的方法:

showViewController

Discussion

This method is used in conjunction with UISplitViewController and UINavigationController. When this method is called, it calls targetViewControllerForAction:sender: on itself and calls this method on the returned object. The target object can then display the view controller in an appropriate way. For example, a navigation controller pushes the view controller on its navigation stack.

If the targetViewControllerForAction:sender: method returns nil, this method uses the root of the currently presented view controller chain to present vc modally.

要点:用于UISplitViewController 、UINavigationController时相当于调用push。如果不是这两者,则相当于presentViewController

showDetailViewController

Discussion

This method is used in conjunction with UISplitViewController and UINavigationController. When this method is called, it calls targetViewControllerForAction:sender: on itself and calls this method on the returned object. The target object can then display the view controller in an appropriate way. For example, a split view controller tries to display the view controller in its secondary view controller slot. If a secondary view controller already exists in that slot, that view controller is asked to present vc in an appropriate way.

If the targetViewControllerForAction:sender: method returns nil, this method uses the root of the currently presented view controller chain to present vc modally.

要点:iPad和6+横屏下SplitView可以显示两个ViewController,使用此方法

pushViewController

Pushes a view controller onto the receiver’s stack and updates the display.

iOS 8 后 Apple 不再提倡使用UINavigationController 的 pushViewController:animated: 方法了

使用show替代

popViewControllerAnimated

popToRootViewControllerAnimated

popToViewController

上面三个方法是push/show对应出栈方法

 

另外

注意点

在导航控制器的应用中,可以这样方便的访问到上一个控制器:

   1:  let a = navigationController!.viewControllers
   2:  let c = a[a.count - 2] as! ContactListViewController

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

进而可以对其上一个控件进行一些修改

viewControllers属性的说明Apple鼓励我们使用这个属性获取当前导航栏的根控制器(0)、上一级控制器(n-2)以及顶层(n-1)控制器

Property

The view controllers currently on the navigation stack.

Declaration

SWIFT

var viewControllers: [AnyObject]!

OBJECTIVE-C

@property(nonatomic, copy) NSArray *viewControllers

Discussion

The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.

Ref:

http://www.cocoachina.com/ios/20141113/10212.html

http://www.cnblogs.com/iMiamas/p/4282568.html

http://stackoverflow.com/questions/28498947/difference-between-pushviewcontroller-and-showviewcontroller

http://mobile.51cto.com/iphone-446761.htm

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html

http://blog.csdn.net/dreamno23/article/details/21085783

iOS中的场景转换机制的浅显分析的更多相关文章

  1. IOS中的沙盒机制

    IOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容.所有的非代码文件都保存在这个地方,比如图片.声音.属性列表和文本文件 ...

  2. iOS中RGB颜色转换

    iOS中RGB常用的色值,同时可将对颜色的设置定义成宏,方便开发应用,如: // RGB颜色转换(16进制->10进制) #define UIColorFromRGB(rgbValue) [UI ...

  3. iOS中消息的传递机制

    本文中,会经常提及接收者[recipient]和发送者[sender].在消息传递机制中具体是什么意思,我们可以通过一个示例来解释:一个table view是发送者,而它的delegate就是接收者. ...

  4. IOS中UITableViewCell的重用机制原理

    创建UITableViewController子类的实例后,IDE生成的代码中有如下段落: - (UITableViewCell *)tableView:(UITableView *)tableVie ...

  5. iOS swift 富文本显示 富文本在iOS中使用场景和解决方案

    项目中很多地方都会用到富文本的内容:比如一般的商品详情,视频详情,资讯详情等,运营人员通过后台的富文本编辑器编辑的内容,前端拿到的就是一段富文本的字符串,这富文本大多都是图片和文字的组合.我们今天介绍 ...

  6. ios中的safari转换时间戳问题

    后台下发的时间格式如:2016-09-15 15:30:10:也没多想,直接用new Date('2016-09-15 15:30:10').getTime()获取时间戳:开发时候,电脑调试OK,当放 ...

  7. Objective-C 中Socket常用转换机制(NSData,NSString,int,Uint8,Uint16,Uint32,byte[])

    最近项目中要用到socket通讯,由于涉及到组包问题,所以需要数据类型之间的来回转换,现在分享出来 如果想要请教Socket的问题请留言,我会随时回答的 1. int类型转16进制hexstring ...

  8. iOS中NSDate常用转换操作整合

    //当前时间格式化, 例:YYYY-MM-dd-EEEE-HH:mm:ss + (NSString *)getCurrentDataWithDateFormate:(NSString *)format ...

  9. C++ STL中vector的内存机制和性能分析

    vecotr是动态数组,顾名思义他可以动态的增加自己的长度. 内存机制: 但是怎样的增加自己的长度? vector有两个函数一个是capacity()返回内存空间即缓冲区的大小,另一个是size()返 ...

随机推荐

  1. css属性选择器应用

    代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...

  2. nginx+webpy+uswgi+jwplayer组合搭建流媒体服务器

    转载自:http://blog.csdn.net/cjsafty/article/details/7892392 目前,由于Flash的流行,网络上绝大多数的微视频网站都采用了Flv格式来播放视频. ...

  3. linux查看操作系统是多少位

    有三种方法: 1.echo $HOSTTYPE 2.getconf LONG_BIT,此处不应该是getconf WORD_BIT命令,在64位系统中显示的是32 3.uname -a 出现" ...

  4. Git菜鸟

    1.git 和svn的差异 git和svn 最大的差异在于git是分布式的管理方式而svn是集中式的管理方式.如果不习惯用代码管理工具,可能比较难理解分布式管理和集中式管理的概念.下面介绍两种工具的工 ...

  5. TCP(二)

    TCP半连接和全连接问题 TCP握手过程详解 如上图所示,关键部分:syns queue(半连接队列)和accept queue(全连接队列) 正常情况下的处理过程如下: 1)当server端收到cl ...

  6. [BZOJ2243][SDOI2011]染色 解题报告|树链剖分

    Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段),如“ ...

  7. ecma 2018, javascript spread syntax behaves like Object.assign

    as the subject. It is only supported in Chrome version 60+, so, first check the version, or just use ...

  8. Codeforces Round #391 A B C D E

    A. Gotta Catch Em' All! 题意 从给定的字符串中选取字符,问可构成多少个\(Bulbasaur\) // 想到柯南里一些从报纸上剪汉字拼成的恐吓信_(:з」∠)_ Code #i ...

  9. Ubuntu10.04中利用V4L2读取摄像头数据并保存成文件【转】

    转自:http://blog.chinaunix.net/uid-29339876-id-4042245.html 利用V4L2读取UVC摄像头数据并保存成视频文件,主要参考http://linuxt ...

  10. HashMap/Hashtable/ConcurrentHashMap区别

    HashMap:每个隔间都没锁门,有人想上厕所,管理员指给他一个隔间,里面没人的话正常用,里面有人的话把这个人赶出来然后用. 优点,每个人进来不耽误都能用:缺点,每一个上厕所的人都有被中途赶出来的危险 ...