https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html#//apple_ref/doc/uid/TP40007457-CH112-SW10

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW1

1,  navigation controller

2,  tab bar controller

3,  split view controller    In portrait mode, only the detail view is displayed. The list view is made available using a popover. However, when displayed in landscape mode, the split view controller displays the contents of both children side by side.4,  page view controller

For a view controller’s contents to be visible to the user, it must be associated with a window. There are many ways you can do this in your app:

  • Make the view controller a window’s root view controller.

  • Make the view controller a child of a container.

  • Show the view controller in a popover control.

  • Present it from another view controller.

Most of the time, you present view controllers to gather information from the user or capture the user’s attention for some specific purpose. Once that purpose is                                                                      completed, the presenting view controller dismisses the presented view controller and returns to the standard app interface. When presenting a view controller, one view controller determines how much of the screen is used to present the view controller. The portion of the screen is called the presentation context By default, the presentation context is defined to cover the window.

The ability to present view controllers is a tool that you have at your disposal for interrupting the current workflow and displaying a new set of views. Most commonly, an app presents a view controller as a temporary interruption to obtain important information from the user.

You can remove all objects in the chain by dismissing the first presented view controller. Dismissing a view controller dismisses not only that view controller but also any view controllers it presented.

Presentation Styles for Modal Views

For iPad apps, you can present content using several different styles. In iPhone apps, presented views always cover the visible portion of the window, but when running on an iPad, view controllers use the value in their modalPresentationStyle property to determine their appearance when presented. Different options for this property allow you to present the view controller so that it fills all or only part of the screen.

Figure 10-4 shows the core presentation styles that are available. (The UIModalPresentationCurrentContext style lets a view controller adopt the presentation style of its parent.) In each presentation style, the dimmed areas show the underlying content but do not allow taps in that content. Therefore, unlike a popover, your presented views must still have controls that allow the user to dismiss the view.

Figure 10-4  iPad presentation styles

For guidance on when to use the different presentation styles, see Modal View in iOS Human Interface Guidelines.

Presenting a View Controller and Choosing a Transition Style

When a view controller is presented using a storyboard segue, it is automatically instantiated and presented. The presenting view controller can configure the destination view controller before it is presented. For more information, see Configuring the Destination Controller When a Segue is Triggered.

If you need to present a view controller programmatically, you must do the following:

  1. Create the view controller you want to present.

  2. Set the modalTransitionStyle property of the view controller to the desired value.

  3. Assign a delegate object to the view controller. Typically, the delegate is the presenting view controller. The delegate is used by the presented view controllers to notify the presenting view controller when it is ready to be dismissed. It may also communicate other information back to the delegate.

  4. Call the presentViewController:animated:completion: method of the current view controller, passing in the view controller you want to present.

The presentViewController:animated:completion: method presents the view for the specified view controller object and configures the presenting-presented relationships between the new view controller and the current view controller. Unless you are restoring your app to some previous state, you usually want to animate the appearance of the new view controller. The transition style you should use depends on how you plan to use the presented view controller. Table 10-1 lists the transition styles you can assign to the modalTransitionStyle property of the presented view controller and describes how you might use each one.

Table 10-1  Transition styles for modal view controllers

Transition style

Usage

UIModalTransitionStyleCoverVertical

Use this style when you want to interrupt the current workflow to gather information from the user. You can also use it to present content that the user might or might not modify.

For this style of transition, content view controllers should provide buttons to dismiss the view controller explicitly. Typically, these are a Done button and an optional Cancel button.

If you do not explicitly set a transition style, this style is used by default.

UIModalTransitionStyleFlipHorizontal

Use this style to change the work mode of your app temporarily. The most common usage for this style is to display settings that might change frequently, such as in the Stocks and Weather apps. These settings can be meant for the entire app or they can be specific to the current screen.

For this style of transition, you usually provide some sort of button to return the user to the normal running mode of your app.

UIModalTransitionStyleCrossDissolve

Use this style to present an alternate interface when the device changes orientations. In such a case, your app is responsible for presenting and dismissing the alternate interface in response to orientation change notifications.

Media-based apps can also use this style to fade in screens displaying media content.

For an example of how to implement an alternate interface in response to device orientation changes, see Creating an Alternate Landscape Interface.

Listing 10-1 shows how to present a view controller programmatically. When the user adds a new recipe, the app prompts the user for basic information about the recipe by presenting a navigation controller. A navigation controller was chosen so that there would be a standard place to put a Cancel and Done button. Using a navigation controller also makes it easier to expand the new recipe interface in the future. All you would have to do is push new view controllers on the navigation stack.

Listing 10-1  Presenting a view controller programmatically

- (void)add:(id)sender {
// Create the root view controller for the navigation controller
// The new view controller configures a Cancel and Done button for the
// navigation bar.
RecipeAddViewController *addController = [[RecipeAddViewController alloc] init]; // Configure the RecipeAddViewController. In this case, it reports any
// changes to a custom delegate object.
addController.delegate = self; // Create the navigation controller and present it.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentViewController:navigationController animated:YES completion: nil];
}

When the user taps either the Done or the Cancel button from the new recipe entry interface, the app dismisses the view controller and returns the user to the main view. See Dismissing a Presented View Controller.

- initWithRootViewController:

Initializes and returns a newly created navigation controller.

Declaration

Swift

init(rootViewController rootViewController: UIViewController)

Objective-C

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController

Parameters


rootViewController

The view controller that resides at the bottom of the navigation stack. This object cannot be an instance of the UITabBarController class.

Return Value

The initialized navigation controller object or nil if there was a problem initializing the object.

Discussion

This is a convenience method for initializing the receiver and pushing
a root view controller onto the navigation stack. Every navigation
stack must have at least one view controller to act as the root.

(navigation在被显示的时候, 其 navigation stack 不允许为空,因此在navigation 被prensted的时候,必须向navigation stack里添加一个root view controller,即navigatorController的第一个view controller。这里的root view controller指的是stack里的,而不是说这个root view controller是navigator的root view controller)

Import Statement

import UIKit

Availability

Available in iOS 2.0 and later.

ios中的容器类 ViewController的更多相关文章

  1. iOS 中关于ViewController总结

    以前写程序时,经常被旋转问题弄的头疼,今天为了解决这个问题,偶然看到了苹果官方文档 View Controller Programming Guide for iOS. 这才发现这个必读的资料!以前许 ...

  2. IOS学习笔记37——ViewController生命周期详解

    在我之前的学习笔记中讨论过ViewController,过了这么久,对它也有了新的认识和体会,ViewController是我们在开发过程中碰到最多的朋友,今天就来好好认识一下它.ViewContro ...

  3. iOS:iOS中的多控制器管理

    iOS中的控制器有三种创建方式: 1.通过storyboard创建 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@" ...

  4. Cordoval在iOS中的运用整理

    一:关于Cordoval理论知识 1:PhoneGap是手机平台上流行的一款中间件.它构建在各种手机平台所提供的WebView(浏览器内核)组件的基础之上,使用javascript语言对应用开发者提供 ...

  5. iOS中集成ijkplayer视频直播框架

    ijkplayer 是一款做视频直播的框架, 基于ffmpeg, 支持 Android 和 iOS, 网上也有很多集成说明, 但是个人觉得还是不够详细, 在这里详细的讲一下在 iOS 中如何集成ijk ...

  6. iOS中JS 与OC的交互(JavaScriptCore.framework)

    iOS中实现js与oc的交互,目前网上也有不少流行的开源解决方案: 如:react native 当然一些轻量级的任务使用系统提供的UIWebView 以及JavaScriptCore.framewo ...

  7. IOS中的多线程之GCD

    在ios中,使用多线程有三种方式,分别是:NSThread.NSOperation和NSOperationQueue.GCD,在本节,主要讲解一下CDD的使用. GCD(Grand Central D ...

  8. iOS中plist的创建,数据写入与读取

    iOS中plist的创建,数据写入与读取 Documents:应用将数据存储在Documents中,但基于NSuserDefaults的首选项设置除外Library:基于NSUserDefaults的 ...

  9. IOS中调用系统的电话、短信、邮件、浏览功能

    iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...

随机推荐

  1. vi 在行首尾添加字符串

    在行首尾添加字符串     用下列命令在文本每行的行首添加字符串“NewString”,请注意空格的存在.      :g/^/s//NewString/g     :%s/^/NewString/g ...

  2. 项目中常用功能,如:流媒体、健康数据(步数等)等-b

    整理iOS开发中使用的各种流媒体和常用的高级功能.由于时间关系,目前只写了一部分功能,全部都采用的是系统方法,没用第三方,截图如下: screen1.png screen2.png 个人比较懒,不爱多 ...

  3. 自定义一个"花瓣"菜单-b

    先来看一下效果 XLCircleMenu.gif 是不是觉得挺好玩的呀. 通过这篇文章你可以学到: 1.系统UITableView的部分设计思想 2.自定义控件常用设计思路 3.动画的具体使用 4.手 ...

  4. CATransition的动画效果类型及实现方法--老代码备用参考

    实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransi ...

  5. pscp实现Windows 和Linux 文件互相传输

    pscp 能够实现Windows 和Linux 间相互传输文件.下文将详细描述如何使用: 一.pscp 简要描述: PSCP (PuTTY Secure Copy client)是PuTTY 提供的文 ...

  6. jsp接收相同复合参数 request.getParameterValues()用法

    在网站中往往需要用户选择复选框,此时需要创建多个复选框让用户进行选择: <head> <meta http-equiv="Content-Type" conten ...

  7. Foundation和UIKit框架图

    学习Foundation和UIKit的时候比较容易忽视的一个问题: 对于一个新的类,知道它的用法和属性方法,但往往忽视了它的继承关系, 了解类的继承关系能帮助加深对其理解. 另外在官方文档中每一个类的 ...

  8. [杂题]URAL1822. Hugo II's War

    看懂题意的请直接跳过下一坨! 本人有表达障碍! ========================================== 题意: (题意真的很难很难懂啊!!!  去他娘的**) 有一个王国 ...

  9. INF文件

    百度百科:http://baike.baidu.com/view/637107.htm?fr=ala0_1_1 INF简介 INF是Device INFormation File的英文缩写,是Micr ...

  10. 【HDOJ】1462 Word Crosses

    字符串水题,这么做可能比较巧妙. /* 1462 */ #include <iostream> #include <string> #include <map> # ...