Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

632

CHAPTER 17: Taps, Touches, and Gestures

This gives us an action method to connect our recognizer to, which in turn triggers the familiar-looking eraseLabel method. Next, edit the viewDidLoad method, adding the following lines, which connect an instance of our new recognizer to the view:

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

BIDCheckMarkRecognizer *check = [[BIDCheckMarkRecognizer alloc] initWithTarget:self action:@selector(doCheck:)];

[self.view addGestureRecognizer:check];

}

All that’s left now is to add the following code to the existing viewDidUnload method:

- (void)viewDidUnload

{

[super viewDidUnload];

//Release any retained subviews of the main view.

//e.g. self.myOutlet = nil;

self.label = nil;

}

Compile and run the app, and try out the gesture.

When defining new gestures for your own applications, make sure you test them thoroughly, and if you can, have other people test them for you as well. You want to make sure that your gesture is easy for the user to do, but not so easy that it gets triggered unintentionally. You also need to make sure that you don’t conflict with other gestures used in your application. A single gesture should not count, for example, as both a custom gesture and a pinch.

Garçon? Check, Please!

You should now understand the mechanism iOS uses to tell your application about touches, taps, and gestures. You also know how to detect the most commonly used iOS gestures, and even got a taste of how you might go about defining your own custom gestures. The iPhone’s interface relies on gestures for much of its ease of use, so you’ll want to have these techniques at the ready for most of your iOS development.

When you’re ready to move on, turn the page, and we’ll tell you how to figure out where in the world you are using Core Location.

www.it-ebooks.info

Chapter18

Where Am I? Finding Your Way with Core Location

Every iOS device has the ability to determine where in the world it is using a framework called Core Location. Core Location can actually leverage three technologies to do this: GPS, cell tower triangulation, and Wi-Fi Positioning Service (WPS).

GPS is the most accurate of the three technologies, but it is not available on firstgeneration iPhones, iPod touches, or Wi-Fi-only iPads. In short, any device with at least a 3G data connection also contains a GPS unit. GPS reads microwave signals from multiple satellites to determine the current location.

NOTE: Technically, Apple uses a version of GPS called Assisted GPS, also known as A-GPS. A-

GPS uses network resources to help improve the performance of stand-alone GPS.

Cell tower triangulation determines the current location by doing a calculation based on the locations of the cell towers in the phone’s range. Cell tower triangulation can be fairly accurate in cities and other areas with a high cell tower density, but it becomes less accurate in areas where there is a greater distance between towers. Triangulation requires a cell radio connection, so it works only on the iPhone (all models, including the very first) and the iPad with a 3G data connection.

The WPS opton uses the MAC addresses from nearby Wi-Fi access points to make a guess at your location by referencing a large database of known service providers and the areas they service. WPS is imprecise and can be off by many miles.

All three methods put a noticeable drain on the battery, so keep that in mind when using Core Location. Your application shouldn’t poll for location any more often than is absolutely necessary. When using Core Location, you have the option of specifying a desired accuracy. By carefully specifying the absolute minimum accuracy level you need, you can prevent unnecessary battery drain.

D.Mark et al., Beginning iOS 5 Development

©Dave Mark, Jack Nutting, Jeff LaMarche 2011

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]