View Controller Programming Guide for iOS--(二)

三,Navigation Controllers

1,Navigation interface
下图展示了navigation interface的关键视图(views)。Navigation view是navigation controller’s view属性,是你嵌入到一个window或使用其他的view controller展示使用的view。
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
2,The Objects of a Navigation Interface:
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
下图显示了navigation controller和navigation stack中的Objects的主要关系。
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

需要注意的是topViewController和visibleViewController属性不一定相同。如果你modally present a view controller,那么topViewController不改变,而visibleViewController改变了。

3,Creating a Navigation Interface:
4,Loading Your Navigation Interface from a Nib File:
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
5,通过代码创建 a Navigation Interface:
 navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
6,Adopting a Full-Screen Layout for Navigation Views:

set wantsFullScreenLayout属性为YES.   如果你正在创建一个navigation interface并且想你的自定义内容占据尽可能多或全部的屏幕,下面是你需要采取的步骤:

1)配置你的自定义view的frame来充满整个屏幕。确认配置你的views的autoresizing 属性as well。 Autoresizing attributes确保了你的view needs to be resized,it adjusts its content accordingly.alternatively(二者选一),当你的view resized,你可以call 你的view的setNeedsLayout方法来indicate(表明,指出)他的subviews的位置应该被调整。

2)设置你的navigation controller的navigationBar.translucent的translucent property为YES。这允许你的content to underlap the navigation bar。

3)To Underlap the status bar,设置你的View Controller的wantsFullScreenLayout属性为YES。(the navigation bar必须是translucent,以便这个属性被识别)。

4)to underlap an optional toolbar,设置toolbar.translucent property  to YES.

当展示你的Navigation Interface的时候,the window或者你的navigation view要添加到的view也必须被sized appropriately(适当地)。如果你使用一个navigation controller作为主interface,then你的main window应该被sized to match(匹配) the screen dimensions(尺寸,容积)。换句话说,你应该设置他的尺寸为匹配UIScreen class的bounds属性(替代 apppicationFrame 属性)。实际上,对于一个navigation interface,创建的window with the full-screen bounds in all situations(在所有情况下)是没错的,因为navigation controller 总是自动地调整他的views的尺寸 to accommodate (容纳,使适应) the status bar。

如果你使用modally展示一个navigation controller,the content presented by that navigation controller is limited by the view controller doing the presenting. If that view controller does not want to underlap the status bar, then the modally presented navigation controller is not going to be allowed to underlap the status bar either. In other words, the parent view always has some influence over how its modally presented views are displayed.

7,Modifying the Navigation Stack:

1)pushViewController:animated: 

2)popViewControllerAnimated:

3)setViewController:animated: 回复navigation stack to a 之前的状态

4)popToRootViewControllerAnimated:

5)popToViewController:animated:

6)setViewControllers:animated:

8,Monitoring Changes to the Navigation Stack:
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
9,Customizing the Navigation Bar Appearance:

1)配置 Navigation Item Object: Navigation Bar由 UINavigationItem组成,which are stored using a stack data structure known as the navigation item stack. Each navigation item provides a complete set of views and content to be displayed in the navigation bar. Unlike a navigation controller, a navigation bar is an actual view object that can be embedded inside other views.

View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

每个Navigation Bar’s stack 总是parallel(平行地) navigation controller’s stack,即一个viewController对应一个Navigation Bar,这种一对一的关系。

一个navigation bar有3个主要位置放置items: left right center.

a)Left位置的属性:backBarButtonItem  leftBarButtonItem

b)center位置的属性:titleView

c)right位置的属性:rightBarButtonItem

下图为Navigation bar structure:

View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

2)显示或隐藏Navigation bar:使用setNavigationBarHidden:animated:,永远不要使用hidden属性。在view Controller的viewWillAppear方法中设置是否显示navigation bar。

3)直接修改 navigation bar Object :在一个navigation interface中,navigation controller拥有他的UINavigationBar对象并且负责管理他,你不能更换NavigationBar或修改他的bounds,frame,or alpha directly.然而,有一些属性你可以使用:

a)barStyle 属性 

b)translucent属性

c)tintColor属性

(省略图)

对于transulucent属性,如果其underlying view controller的main view是一个scroll view,那这个属性没有什么作用,navigation bar自动调整 将navigation bar下面的内容scroll out。对于其他类型的views将不做此调整。

4)使用自定义的按钮和视图作为Navigation Items:

使用视图控制器的navigationItem属性获得导航控制条,可以设置其leftBarButtonItem、leftBarButtonItems、title、titleView、rightBarButtonItem、rightBarButtonItems、leftItemsSupplementBackButton属性
如果视图控制器不修改导航项,那导航控制器提供一系列默认的对象,能满足你大部分情形。当然,你所做的任何的自定义的行为优先于默认的对象:
对于顶端的视图控制器来说,导航栏左边的项的显示取决于下面的规则:
1)如果视图控制器指定了navigationItem. leftBarButtonItem,他将优先显示。
2)如果你没有设置,而他的下一级视图控制器设置了backBarButtonItem属性,则显示他。
3)如果都没有,则显示下一级视图控制器的标题title属性.

显示在中间的内容按下面的规则显示:
A)显示navigationItem.titleView。
B)显示navigationItem.title。
C)显示视图控制器的Title。

右边显示的内容规则:
A)显示navigationItem.rightBarButtonItem
B)不显示任何内容.

下图展示了自定义的buttons

(省略)

创建自定义button的代码:

// View 3 - Custom right bar button with a view

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];

self.navigationItem.rightBarButtonItem = segmentBarItem;

你应该在viewDidLoad方法中创建的items.

5)Using Edit and Done Buttons: 在显示和edit modes之间切换。UIViewController的 editButtonItem方法返回一个预配置的button,当点击他时就切换Edit and Done按钮,并调用viewcontroller’s setEditing:animated:方法。使用下面的方法添加:

myViewController.navigationItem.rightBarButtonItem = [myViewController editButtonItem];

10,Displaying a navigation toolbar::为你的navigation interface配置toolbar:

1)设置toolbarHidden属性为NO。

2)Assign an array of UIBarButtonItem object to toolbarItems 属性。
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

创建代码:

   UIBarButtonItem *flexibleSpaceButtonItem = [[UIBarButtonItem alloc]

                        initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace

                        target:nil action:nil];

   UIBarButtonItem *sortToggleButtonItem = [[UIBarButtonItem alloc]

                                    initWithCustomView:sortToggle];

   // Set our toolbar items

   self.toolbarItems = [NSArray arrayWithObjects:

                         flexibleSpaceButtonItem,

                         sortToggleButtonItem,

                         flexibleSpaceButtonItem,

                         nil];



除了可以在初始化时创建toolbar,viewController还可以使用setToolbarItems:animated:动态更改其toolbar。

11,显示和隐藏Toolbar:要为一个特定的viewController隐藏一个toolbar,需要设置hidesBottomBarWhenPushed属性为YES。Navigation controller会generate(使发生,形成)合适的动画—在viewcontroller被推入或(移除出)导航栈.

如果你想在某时隐藏,你可以使用navigation Controller的方法setToolbarHidden:animated: ,一般都是和setNavigationBarHidden:animated:一起使用,来创建一个临时的全屏幕view。

四,Tab Bar Controllers

1,介绍
每个viewController被定义成每个tabs的root view Controller in the tab bar view。下图展示了时钟app的界面,
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
2,Tab Bar Interface的组成:
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

如果viewControllers属性超过5个items,tab bar controller会自动添加一个more view controller来处理显示附加的items。你可以通过UITabBarController的moreNavigationController属性获得他,但是不能被customized,并且不会显示在任何的被tab bar controller管理的view Controller列表中。他会自动地在需要的时候显示并且与你的custom content 隔离。

虽然tab bar view是一个关键的部分,但是你不能直接修改他。The tab bar controller object assembles(集合,聚集) the contents of the tab bar from the UITabBarItem objects provided by you custom view Controllers。下图展示了他们之间的关系。
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

因为tab bar item用来配置tab bar,所以你必须首先配置每个view controller的tab bar item。如果你正在使用IB,你可以定制title和image在nib file中。如果你使用代码,你必须创建一个新的UITabBarItem。

3,Creating a tab bar interface:
4,Defining the Custom View Controllers for a tab bar interface:
5,Creating a tab bar interface Using a Nib File:
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
6,Creating a Tab Bar Interface Programmatically:
tabBarController.viewControllers = controllers;
7,Creating a Tab Bar Item programmatically:

      UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"];

      UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:anImage tag:0];

      self.tabBarItem = theItem;

8,Managing tabs at runtime:

使用delegate object

1)Adding and Removing tabs:  使用setViewControllers:animated:方法重新设置viewControllers列表。代码:

2)Preventing the Selection of Tabs:使用delegate object的tabBarController:shouldSelectViewController:方法返回的BOOL值。如下:

3)Monitoring user-initiated tab changes:有两种类型的user-initiated changes:

a)用户可以选择一个tab

b)用户可以重新排列tabs

每种类型的更改都are reported to tab bar controllers’s delegate(遵循UITabBarControllerDelegate协议)。

9,Preventing the Customization of tabs:

当你希望用户可以重新排列tabs,你可以指定一个an array of view controller objects to the  CustomizableViewController属性。

重要:添加或移除view controllers在你的tab bar interface中也重置了customizable view controller的数组为default value,允许所有的view controllers to be customized again。因此,如果你修改了viewControllers属性(或调用了setViewControllers:animated:方法)并且还想limit the customizable view controllers,你必须也更新the array of objects in the customizableViewControllers属性.


10,Changing a tab’s badge:
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 

要想设置a badge to a tab,需要指定一个non-nil value到相应的tab bar item的badgeValue属性。例如,一个viewController要在他的badge中显示新items的数量,使用下面类似的代码:

   self.tabBarItem.badgeValue = nil;

需要由你来决定何时显示badge values and 更新badge value在合适的时候。然而,如果你的view Controller包含一个property with such a value,你可以使用KVO notifications to detect(检测) changes to the value and update the badge accordingly。

11,Tab bar controllers and view Rotation:除非每个ViewControlelr都支持rotation,否则tabbar不会支持rotation

12,Tab bars and full-Screen layout:

你仍然可以使用wantsFullScreenLayout属性。

五,iPad-Specific Controllers

1,Popovers:
2,Split View Controller:

六,Modal View Controllers

1,介绍
当你modal一个ViewController时,系统创建了一个父子关系。特别地,显示Modal的viewController更新他的modalViewController的属性指向他显示的viewController。同样地,被显示的viewController更新TA的parentViewController属性指向显示他的viewController。
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
每个ViewController都可以modal另一个single view Controller,甚至是他们自己本身。
2,Configuring the Presentatin Style for Modal Views:

对于iPad,你可以使用几种不同的styles显示modally view,对于iPhone,modally view总是覆盖可见的window部分,但是运行于iPad上时,view Controller使用modalPresentationStyle属性来决定他们的显示方式,是显示可见区域还是全屏。

下图显示了core presentation styles( the UIModalPresentationCurrentContext style使一个view Controller采用其parent的presentation style)。
View Controller Programming Guide for iOS--(二) - supershll - 记忆里
 
3,Presenting a View Controller Modally:

1)创建一个要modal的view Controller;

2) 设置viewController的 modalTransitionStyle 属性。

3)指定一个delegate object 。

4)调用 presentModalViewController:animated: 方法。

 

关于modalTransitionStyle:

UIModalTransitionStyleCoverVertical:垂直方向滑入视图。这是默认的style。
UIModalTransitionStyleFlipHorizontal:水平反转方式显示视图
UIModalTransitionStyleCrossDissolve:淡入淡出方式
你需要显式地指定取消视图控制器的按钮,如Done 和 cancel按钮
还有一种样式:
UIModalTransitionStylePartialCurl
半翻页效果,能自动取消显示,不用指定返回按钮。
4,Dismissing a Modal View Controller:
5,Presenting Standard System Modal View Controllers:

使用标准系统Modal View Controllers:

每个系统view Controller都声明了一个相应的protocol(协议),你可以在你的delegate对象中实现他们的方法。一般delegate实现选择或者取消操作的方法的实现。你的delegate对象应该总是准备好处理这两种情形。一项最重要的事情就是dismiss ModalViewController(通过调用dismissModalViewControllerAnimated:方法)。

下表列出了一些 standard system view controllers in iOS。更多信息请参看其类信息。

Address Book UI提供的viewControllers:ABNewPersonViewController,ABPeoplePickerNavigationController,ABPersonViewController,ABUnknownPersonViewController。

 

Event Kit UI提供的: EKEventViewController,EKEventEditViewController

 

Game Kit提供的: GKPeerPickerController,GKAchievementViewController,GKMatchmakerViewController,GKLeaderboardViewController

 

Message UI提供的:MFMailComposeViewController,MFMessageComposeViewController

 

Media Player提供的:MPMediaPickerController,MPMoviePlayerViewController

 

UIKit提供的: UIImagePickerController, UIVideoEditorController

 

注意:虽然在Media Player框架中的MPMoviePlayerController class 可能technically(技术上,学术上)被认为是一个modal Controller,但semantics(语义上)使用他有一些差别。 Instead of presenting the view controller yourself,you initialize it and tell it to play its media file. The View controller then handles all aspects of presenting and dismissing its view. (However ,the MPMoviePlayerViewController class can be used instead of MPMoviePlayerController as a standard view Controller for playing movies.)

七,Combined View Controller Interfaces

UIKit框架提供了only a handful of(一把,少量的) standard view controllers:

1)Custom view Controller

2)navigation controller

3)Tab bar controller

4)split view controller

 

你可以单独使用这些viewController, or in conjunction with(连同,共同,与---协力) other view Controllers来创建更复杂的界面。

下面的章节告诉你如何结合table view,navigation and tab bar controllers in your iOS applications.

 

1,Adding a Navigation Controller to a Tab Bar Interface:
2,Creating the Objects in IB:
3.Creating Objects Programmatically:
5,Displaying a Tab Bar Controller Modally:
6,Using Table View Controllers in a Navigation Interface
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值