28
Multiview Applications 1 [email protected] Mobile Applications

Beginning iOS6 Development CH06 Multiview Applications

Embed Size (px)

DESCRIPTION

Beginning iOS6 Development CH06 Multiview Applications

Citation preview

Page 1: Beginning iOS6 Development CH06 Multiview Applications

Multiview Applications

[email protected] Applications

Page 2: Beginning iOS6 Development CH06 Multiview Applications

Types of Multiview Apps

• Utility Applications

• Tab bar applications

• Navigation-based applications

• Toolbar applications

[email protected] Applications

Page 3: Beginning iOS6 Development CH06 Multiview Applications

Utility Applications

• A utility application focuses primarily on a single view but offers a secondview that can be used to configure the application or to provide more detail than the primary view

−The Stocks application that ships with iPhone has two views: one to display the data and another to configure the stock list

[email protected] Applications

Page 4: Beginning iOS6 Development CH06 Multiview Applications

Tab bar applications

• A tab bar application is a multiviewapplication that displays a row of buttons, called the tab bar, at the bottom of the screen. Tapping one of the buttons causes a new view controller to become active and a new view to be shown. such as The Phone application

[email protected] Applications

Page 5: Beginning iOS6 Development CH06 Multiview Applications

Navigation-based applications

• The navigation-based application features a navigation controller that uses a navigation bar to control a hierarchical series of views.

– The navigation controller keeps track of how deep you go and gives you a control to let you make your way back to the previous view.

[email protected] Applications

Page 6: Beginning iOS6 Development CH06 Multiview Applications

Toolbar applications

• Some applications make use of a toolbar.

• Tab bar vs. Toolbar

– A tab bar is used for selecting one and only one option from among two or more.

– A toolbar can hold buttons and certain other controls, but those items are not mutually exclusive.

[email protected] Applications

Page 7: Beginning iOS6 Development CH06 Multiview Applications

The Architecture of a Multiview Application

• S

[email protected] Applications

Page 8: Beginning iOS6 Development CH06 Multiview Applications

The Root Controller

• The root controller is the primary view controller for the application.

• It is the first controller the user sees and the controller that is loaded when the application loads.

[email protected] Applications

Page 9: Beginning iOS6 Development CH06 Multiview Applications

Anatomy of a Content View

• Each content view generally consists of up to three pieces:

• The view controller.

• The nib.

• Subclass of UIView.

[email protected] Applications

Page 10: Beginning iOS6 Development CH06 Multiview Applications

UINavigationController

• Create a new project using the Empty Application project template

[email protected] Applications

Page 11: Beginning iOS6 Development CH06 Multiview Applications

Creating View Controller and Nib Files

• Create a new Objective-C Class BIDSwitchViewController.– File ➤ New ➤ File, select Cocoa Touch from the left

pane, select Objective-C Class.

• 2 more and name them BIDBlueViewController & BIDYellowViewController.

• Create a nib file for each of the content views.– File ➤ New ➤ File, select User Interface from the left

pane, select View.(SwitchView.xib, BlueView.xib YellowView.xib)

[email protected] Applications

Page 12: Beginning iOS6 Development CH06 Multiview Applications

Modifying the App Delegate

• In BIDAppDelegate.h:

• In BIDAppDelegate.m:

[email protected] Applications

Page 13: Beginning iOS6 Development CH06 Multiview Applications

Modifying the App Delegate

[email protected] Applications

Page 14: Beginning iOS6 Development CH06 Multiview Applications

Modifying BIDSwitchViewController.h

[email protected] Applications

Page 15: Beginning iOS6 Development CH06 Multiview Applications

Adding a View Controller

• Change File’s Owner Class field from NSObjectto BIDSwitchViewController.

– SwitchView.xib

[email protected] Applications

Page 16: Beginning iOS6 Development CH06 Multiview Applications

Building a View with a Toolbar

• Drag a toolbar onto the view, rename its button title to Switch Views.

• control-drag from it over to the File’s Owner icon and select the switchViews: action.

– make sure you have the button rather than the toolbar selected.

[email protected] Applications

Page 17: Beginning iOS6 Development CH06 Multiview Applications

Writing the Root View Controller

• In BIDSwitchViewController.m:(Top)

• In viewDidLoad:

[email protected] Applications

Page 18: Beginning iOS6 Development CH06 Multiview Applications

Writing the Root View Controller

• in the switchViews: method:

[email protected] Applications

Page 19: Beginning iOS6 Development CH06 Multiview Applications

Writing the Root View Controller

• In didReceiveMemoryWarning method:

Mobile Applications [email protected] 19

Page 20: Beginning iOS6 Development CH06 Multiview Applications

Implementing the Content Views

• in BIDBlueViewController.h:

• In BIDYellowViewController.h:

Mobile Applications [email protected] 20

Page 21: Beginning iOS6 Development CH06 Multiview Applications

Implementing the Content Views

• Change File’s Owner Class field from NSObjectto BIDBlueViewController for BlueView.xib & to BIDYellowViewController for YellowView.xib.

• Then change the background color of both views to blue & yellow.

Mobile Applications [email protected] 21

Page 22: Beginning iOS6 Development CH06 Multiview Applications

Implementing the Content Views

• Then change the size of the view in the nib

Mobile Applications [email protected] 22

Page 23: Beginning iOS6 Development CH06 Multiview Applications

Implementing the Content Views

• Then Drag a Round Rect Button to BlueView.xib (Press Me) drag from the Touch Up Inside event to the File’s Owner icon, and connect to the blueButtonPressed action method.

• Control-drag from the File’s Owner icon to the View icon, and select the view outlet.– Do the same with YellowView.xib with changing

names.

Mobile Applications [email protected] 23

Page 24: Beginning iOS6 Development CH06 Multiview Applications

Implementing the Content Views

• In BIDBlueViewController.m:

Mobile Applications [email protected] 24

Page 25: Beginning iOS6 Development CH06 Multiview Applications

Implementing the Content Views

• In BIDYellowViewController.m:

Mobile Applications [email protected] 25

Page 26: Beginning iOS6 Development CH06 Multiview Applications

Animating the Transition

• In BIDSwitchViewController.m:

Mobile Applications [email protected] 26

Page 27: Beginning iOS6 Development CH06 Multiview Applications

Animating the Transition

Mobile Applications [email protected] 27

Page 28: Beginning iOS6 Development CH06 Multiview Applications

Animating the Transition

• Some iOS view transitions:

– UIViewAnimationTransitionFlipFromLeft

– UIViewAnimationTransitionFlipFromRight

– UIViewAnimationTransitionCurlUp

– UIViewAnimationTransitionCurlDown

Mobile Applications [email protected] 28