UINavigationController
class
implements a specialized view controller that manages the navigation of hierarchical content. UINavigationController
类为管理具有一定层次结构的内容实现了专门的视图控制器。数组的最后一个视图控制器表示当前显示的视图控制器。
pushViewController:animated:
method.Pushing
a view controller displays its view in the navigation interface and updates the navigation controls accordingly. pushViewController:animated:
方法。当push一个视图控制器时,视图控制器会将它自己的视图显示到导航界面并更新对应的导航控制。popViewControllerAnimated:
method. popViewControllerAnimated:
方法。UINavigationControllerDelegate
protocol.假设你想运行一些附加的设置或者清理一些与视图控制器的push或pop操作相关的任务时,你能够指派一个托付对象给你的导航控制器。这个托付对象必须遵守UINavigationControllerDelegate
协议。
view
property.
This view incorporates the navigation bar, an optional toolbar, and the content view corresponding to the topmost view controller. 你能够通过view
属性訪问导航控制器的view。这个view包含一个navigation
bar、一个toolbar、和最顶层视图控制器的内容视图。
frame
, bounds
,
or alpha
values
directly. If you subclass UINavigationBar
,
you must initialize your navigation controller using the initWithNavigationBarClass:toolbarClass:
method.
To hide or show the navigation bar, use the navigationBarHidden
property
or setNavigationBarHidden:animated:
method.它同意开发人员定制navigation
bar显示相关的属性,可是你不能直接去改动它的frame
, bounds
或alpha
值。假设你子类化了UINavigationBar
。你必须使用initWithNavigationBarClass:toolbarClass:
方法初始化你的导航控制器。显示或隐藏navigation
bar,能够设置其navigationBarHidden
属性。或使用setNavigationBarHidden:animated:
方法。
UINavigationItem
class)
associated with the view controllers on the navigation stack. To change the contents of the navigation bar, you must therefore configure the navigation items of your custom view controllers. For more information about navigation items, see UINavigationItem
Class Reference.UINavigationItem
类的实例)动态的构建navigation
bar的内容,因此想要改变navigation bar的内容,你必须配置你自己定制的视图控制器的navigation items。关于UIBarButtonItem
class.
You can create items with custom content or create standard system items depending on your needs. For more information about how to create bar button items, see UIBarButtonItem
Class Reference.UIBarButtonItem
类的实例。你能够依据你的须要用自己定义的内容创建items。也能够创建系统标准的items。很多其它关于怎样创建button items的内容,请阅读UIBarButtonItem Class Reference。
这个最左側的button的内容由下面规则决定:
- If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the
leftBarButtonItem
property of the view controller’s navigation item.
- 假设新的顶层视图控制器有一个定制的 left bar button item。那么这个item会显示。
能够通过设置新的顶层视图控制器navigation item的
leftBarButtonItem
属性指定一个定制的left bar button item。
- If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has an object in its
backBarButtonItem
property, the navigation bar displays that item.
- 假设顶层视图控制器没有定制的bar button item,可是前一个视图控制器navigation item的
backBarButtonItem
属性里面有一个对象,navigation bar将会显示这个item。
- If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the
title
property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
- 假设视图控制器都没有指定定制的bar button item,那么将会显示一个默认的返回button。它的标题会被设置为前一个视图控制器的
title
属性的值,前一个视图控制器也就是在导航栈中比当前视图控制器低一个层级的视图控制器。(假设仅有一个视图控制器在导航栈里面。那么返回button将不会显示。)
NOTE
leftBarButtonItem
or leftBarButtonItems
property
of its navigation item—the navigation bar does not change the button title.leftBarButtonItem
和 leftBarButtonItems属性有对象,navigation
bar不会改动button标题。
-
If the new top-level view controller has a custom title view, the navigation bar displays that view in place of the default title view. To specify a custom title view, set the
titleView
property of the view controller’s navigation item.
- 假设新的顶层视图控制器有一个定制的title view,navigation bar会显示这个定制的title view替换掉默认的title view。能够通过设置视图控制器navigation item的
titleView
属性指定一个定制的title view。
- If no custom title view is set, the navigation bar displays a label containing the view controller’s default title. The string for this label is usually obtained from the
title
property of the view controller itself. If you want to display a different title than the one associated with the view controller, set thetitle
property of the view controller’s navigation item instead.
- 假设没有设置定制的title view,navigation bar就显示包括视图控制器默认标题的一个标签。这个标签的字符串一般是从视图控制器自己的
title
属性获得的。假设你想显示一个与视图控制器相关联的标题不同样的标题。你能够设置视图控制器navigation item的title
属性。
- If the new top-level view controller has a custom right bar button item, that item is displayed. To specify a custom right bar button item, set the
rightBarButtonItem
property of the view controller’s navigation item.
- 假设新的顶层视图控制有一个定制的right bar button item。这个item将会被显示。能够通过设置视图控制器navigation item的
rightBarButtonItem
属性指定一个定制的right bar button item。
- If no custom right bar button item is specified, the navigation bar displays nothing on the right side of the bar.
- 假设没有定制的right bar button item,navigation bar的右側就什么都不会显示。
tintColor
property
to change the tint color of items in the bar and use the barTintColor
property
to change the tint color of the bar itself. Navigation bars do not inherit their tint color from the currently displayed view controller.tintColor
属性改变navigation
bar中items的tint color,使用barTintColor
属性改变navigation
bar自身的tint color。navigation bar不会从当前显示的视图控制器来继承tint
color。toolbarItems
property
of the active view controller. When the active view controller changes, the navigation controller updates the toolbar items to match the new view controller, animating the new items into position when appropriate.toolbarItems
属性获取它当前的items的集合。当活动的视图控制器发生改变。导航控制器就会更新toolbar的items以匹配新的视图控制器,并动画新的items到合适的位置。
setToolbarHidden:animated:
method
of your navigation controller object. If not all of your view controllers support toolbar items, your delegate object can call this method to toggle the visibility of the toolbar during subsequent push and pop operations. To use a custom UIToolbar
subclass,
use the initWithNavigationBarClass:toolbarClass:
method
to initialize the navigation controller.setToolbarHidden:animated:
方法将它设置为显示。假设你并非全部的视图控制器都支持toolbar
items,你能够在随后的push或pop操作时。用托付对象发送这个消息来让toolbar隐藏或显示。假设要使用一个自己定义的UIToolbar
子类。须要使用initWithNavigationBarClass:toolbarClass:
方法初始化导航控制器。
restorationIdentifier
property,
it attempts to preserve the child view controllers on its navigation stack. The navigation controller starts at the bottom of the stack and moves upward, encoding each view controller that also has a valid restoration identifier string. During the next launch
cycle, the navigation controller restores the preserved view controllers to the navigation stack in the same order that they were preserved.restorationIdentifier
属性指定一个值,它会试图去保存它所在的导航栈里面的子视图控制器。导航控制器从栈底開始向上移动。编码每个有有效恢复标识字符串的视图控制器。在下一次的启动循环中。导航控制器依照之前保存的顺序恢复视图控制器到导航栈中。