Chapter 9. Utility Applications

WHAT YOU WILL LEARN IN THIS CHAPTER

  • How to develop a Utility Application using the template provided by the SDK

  • Understand how to flip views in a Utility Application

  • How to apply different transition styles when flipping views

  • How to add additional views to a Utility application

The previous two chapters have demonstrated quite a few types of applications you can build using the iPhone SDK: View-Based applications, Navigation-Based applications, and Tab Bar applications. Another type of application that is prevalent in the iPhone is Utility Applications. A Utility Application is an application that performs simple tasks requiring minimum user inputs. The Weather and Stocks applications that come with your iPhone are two great examples of utility applications. Figure 9-1 shows the Weather application showing the weather of a particular city. When you touch the small i icon located at the bottom-right corner of the screen, the screen flips to another screen. The flipping of views is one of the characteristics of a Utility Application.

Figure 9-1

Figure 9.1. Figure 9-1

According to Apple's UI guidelines for iPhone applications, a Utility Application "performs a simple task that requires a minimum of user input." Hence, if you are developing an application that shows a summary of information that the user can digest quickly, the Utility Application would be the ideal application framework to focus on. Some good examples of Utility Applications include:

  • Currency exchanges

  • Units conversion calculators

  • RSS readers

Hence, in this chapter, you will learn how to build Utility Applications using the template included in the iPhone SDK.

CREATING UTILITY APPLICATIONS

The iPhone SDK includes a template for building Utility Applications. Using the template, all the necessary coding needed to flip the views is created for you. If you are building a simple Utility Application, you just need to focus on your application logic. If you are building a more sophisticated Utility Application, the generated code provides a very good base for you to use to extend the application.

To get started, create a Utility Application using the template in the SDK and learn about how it works in the following Try It Out.

TRANSITIONING STYLES

In the previous section, you saw that when you press the i info button, the view flips to reveal another View. This is controlled by the modalTransitionStyle property of the ViewController class:

- (IBAction)showInfo {

    FlipsideViewController *controller = [[FlipsideViewController alloc]
                                         initWithNibName:@"FlipsideView"
                                         bundle:nil];
    controller.delegate = self;

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];

    [controller release];
}

Note

The modalTransitionStyle property is available only in the iPhone SDK 3.0. If you try to run your application using an older version of the SDK, it will not work.

The default transitioning is the horizontal flip, in which the main view flips horizontally (see Figure 9-6) to reveal the FlipsideView.

Figure 9-6

Figure 9.6. Figure 9-6

Besides flipping horizontally, you can also flip the view vertically or make it dissolve slowly. These features are controlled by the following constants (shown in bold):

//---flip vertically---
    controller.modalTransitionStyle =
UIModalTransitionStyleCoverVertical;

    //---dissolves slowly to reveal another view---
    controller.modalTransitionStyle =
UIModalTransitionStyleCrossDissolve;

As an exercise, you should try modifying the transition styles to see for yourself how they differ.

ADDING ANOTHER VIEW TO THE UTILITY APPLICATION

Now that you have seen how to create a Utility Application using the template provided by the SDK, you might want to add more views to the application so that it has more functionality. Back at the Weather application on the iPhone, observe that the flip side view has an additional plus (+) button that allows you to add more weather information (see Figure 9-7).

Figure 9-7

Figure 9.7. Figure 9-7

In the following Try It Out, you can see how to add another View to the project created earlier so that it behaves like the Weather application.

SUMMARY

In this chapter, you saw the Utility Application template provided by the iPhone SDK to help developers create Utility Applications. Understanding how the transitioning between the Views works is important because it allows you to extend the template for your custom use. In Chapter 10, you will see how Utility Applications are often used together with application settings to persist users" preferences and data.

EXERCISES

  1. Observe that as you click on the Info button of a Utility Application, the Info button is highlighted. How do you turn off the effect?

  2. How you pass data from one view to another in a Utility Application? Assume that you need to pass a string from the FlipsideViewController to the MainViewController.

  • WHAT YOU HAVE LEARNED IN THIS CHAPTER

TOPIC

KEY CONCEPTS

Create a Utility Application

Use the Utility Application template provided by the iPhone SDK.

Transition between views in a Utility Application

Use the modalTransitionStyle property and set it to one of the following values: UIModalTransitionStyleFlipHorizontal, UIModalTransitionStyleCoverVertical, and UIModalTransitionStyleCrossDissolve.

Add a new view to a Utility Application

First, create a new XIB file and its accompanying UIViewController subclass (.h and .m files). Next, define a protocol in the view controller and expose an instance of the protocol delegate as a property.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.126.122