iOS中的场景转换机制的浅显分析

目前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属性的说明

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

时间: 2024-09-30 01:52:06

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

IOS中的沙盒机制

IOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容.所有的非代码文件都保存在这个地方,比如图片.声音.属性列表和文本文件等. 1.每个应用程序都在自己的沙盒内 2.不能随意跨越自己的沙盒去访问别的应用程序沙盒的内容 3.应用程序向外请求或接收数据都需要经过权限认证 查看模拟器的沙盒文件夹在Mac电脑上的存储位置,首先,这个文件夹是被隐藏的,所以要先将这些文件显示出来,打开命令行: 显示Mac隐藏文件的命令:defau

Android 中View的绘制机制源码分析 三

到目前为止,measure过程已经讲解完了,今天开始我们就来学习layout过程,不过在学习layout过程之前,大家有没有发现我换了编辑器,哈哈,终于下定决心从Html编辑器切换为markdown编辑器,这里之所以使用"下定决心"这个词,是因为毕竟Html编辑器使用好几年了,很多习惯都已经养成了,要改变多年的习惯确实不易,相信这也是还有很多人坚持使用Html编辑器的原因.这也反应了一个现象,当人对某一事物非常熟悉时,一旦出现了新的事物想取代老的事物时,人们都有一种抵触的情绪,做技术的

Android 中View的绘制机制源码分析 二

尊重原创:http://blog.csdn.net/yuanzeyao/article/details/46842891 本篇文章接着上篇文章的内容来继续讨论View的绘制机制,上篇文章中我们主要讲解了View的measure过程,今天我们就来学习ViewGroup的measure过程,由于ViewGroup只是一个抽象类,所以我们需要以一个具体的布局来分析measure过程,正如我上篇文章说的,我打算使用LinearLayout为例讲解measure过程,如果你还没有读过上篇文章,那么建议你先

iOS中RGB颜色转换

iOS中RGB常用的色值,同时可将对颜色的设置定义成宏,方便开发应用,如: // RGB颜色转换(16进制->10进制) #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue 

iOS中消息的传递机制(KVO、Notification、delegation、block以及target-action)---转载

注1:本文由破船[博客]译自Communication Patterns. 本文目录如下所示: 可用的机制 做出正确的选择 Framework示例 小结 每个应用程序或多或少,都由一些松耦合的对象构成,这些对象彼此之间要想很好的完成任务,就需要进行消息传递.本文将介绍所有可用的消息传递机制,并通过示例来介绍这些机制在苹果的Framework中如何使用,同时,还介绍了一些最佳实践建议,告诉你什么时机该选择使用什么机制. 虽然这一期的主题是关于Foundation Framework的,不过本文中还

iOS中消息的传递机制

小结 每个应用程序或多或少,都由一些松耦合的对象构成,这些对象彼此之间要想很好的完成任务,就需要进行消息传递.本文将介绍所有可用的消息传递机制,并通过示例来介绍这些机制在苹果的Framework中如何使用,同时,还介绍了一些最佳实践建议,告诉你什么时机该选择使用什么机制. 虽然这一期的主题是关于Foundation Framework的,不过本文中还介绍了一些超出Foundation Framework(KVO和Notification)范围的一些消息传递机制,另外还介绍了delegation,

Android 中View的绘制机制源码分析 一

尊重原创: http://blog.csdn.net/yuanzeyao/article/details/46765113 差不多半年没有写博客了,一是因为工作比较忙,二是觉得没有什么内容值得写,三是因为自己越来越懒了吧,不过最近我对Android中View的绘制机制有了一些新的认识,所以想记录下来并分享给大家.在之后的几篇博客中,我会给大家分享如下的内容: 1.View中measure(),layout(),draw()函数执行过程分析,带领大家详细分析View的尺寸测量过程,位置计算,并最终

ios中的safari转换时间戳问题

后台下发的时间格式如:2016-09-15 15:30:10:也没多想,直接用new Date('2016-09-15 15:30:10').getTime()获取时间戳:开发时候,电脑调试OK,当放到触屏调试的时候,AndroidOK,但是ios也不行了,结果是:NaN-NaN1-NaN Invalid Datewhat?后面了解到:ios能读取的格式是:2016/09/15 15:30:10好吧,那一写成转换时间戳的统一方法来调用: exports.exchangeTime = functi

iOS 中NSArray NSSet转换 过滤重复与排序操作

很久没写ios代码.最近和朋友聊天时候有强迫症,想强烈把代码给优化. 问题是这样的:现在数据是日期数组,想过滤掉重复的日期,怎么解决. 原始代码 这里想到更简洁点.用NSSet来搞定. [objc] view plaincopy NSArray *arr = @[@"12-11", @"12-11", @"12-11", @"12-12", @"12-13", @"12-14"]; NS