Tải bản đầy đủ - 0 (trang)
Chapter 7. Migrating to iPad: We need more room

Chapter 7. Migrating to iPad: We need more room

Tải bản đầy đủ - 0trang

long exercise solution



Use Xcode to edit the view so that the SplitViewController delegate

outlet is talking to the DrinkDetailViewController.

You’ll have to open up the iPad main window and expand the Split View Controller to

make the connection.



4



- (void)drinkChanged:(NSDictionary *)newDrink {



Do this!









One last thing—the drinkChanged

method needs a quick update.

}



self.drink = newDrink;

[self refreshView];



if (popOver_ != nil) {

}



[popOver_ dismissPopoverAnimated:YES];



our popover

Here we make sure to dismiss nk.

dri

if the user selects a new

354   Chapter 7

www.it-ebooks.info



DrinkDetailViewController.m



migrating to iPad



Test Drive



Everything should be working now! Try using

the button and rotating the simulator.



It works!



you are here 4   355

www.it-ebooks.info



no dumb questions



Q:



The detail view still doesn’t look all

that great. Shouldn’t we fix that?



A:



If we were going up on the App Store,

yes. In our next iPad app, later in the book,

we’re going to focus a lot more on look and

feel. For now, we wanted you to get the

controls figured out.



Q:



When we enabled various launch

orientations in Xcode, what did that

actually do?



A:



If you take a look at your Info.plist in

your project, you’ll see that Xcode quietly

added an array of enumerations that list the

launch orientations you support. The GUI

option we used is just a convenience (and

new in Xcode 4) for setting those values.

iOS looks at your app’s Info.plist to figure out

what launch orientations it can use.



Q:



You mentioned the ~ipad thing was

standard. Standard for what?



A:



Before the iPad, launch screens were

simply named Default.png, then DefaultPortrait.png and Default-Landscape.png.

Once the iPad entered the scene, Apple

added the concept of ~ to filenames.

iOS will pick the most appropriate file based

on device type. It does something similar

with the @2x notation for high-resolution

(iPhone 4 Retina display).



Q:



Are popovers only used with Split

View Controllers?



A:



Most definitely not! Popovers are used

pretty often in iPad applications. They’re

very straightforward to use—they simply

wrap a view and you can tell them which

control they should appear next to. See the

documentation for UIPopoverController for

more information.



Q:



We really didn’t do much to

support the various screen orientations.

Is that normal?



A:



It really depends on your application.

When you edit the size information of a

control in Xcode, you can set its Autoresizing

properties. With those properties, you can

anchor a control to the top, bottom, or sides

and control whether it stretches when the

view changes size (which is typically due to

a rotation). If you’re using roughly the same

layout for both landscape and portrait (which

we are, minus the table view), you can use

Autosizing to get you what you want.



For more complicated views, you might hide

or show entire controls or resize and relayout controls depending on the orientation.

There are a number of view controller

callbacks that will get called while the view

is rotating to its new orientation, and in

there you can update the size, position,

and visibility of your controls if necessary.



356   Chapter 7

www.it-ebooks.info



Typically, you’ll use view animations here to

make sure things transition smoothly.



Q:



What happens if I try to use a

popover on the iPhone?



A:



Very, very bad things. There are

controls and features that only exist on a

particular device (and within a particular iOS

version). When the iPad first came out, you

couldn’t even rely on there being a class

name UIPopoverController on the iPhone.

Now that’s gotten a little simpler, but you

must always check that you’re on a particular

device or that the device has the feature you

are about to use before trying to do it.

Depending on what versions of iOS you

support, you will also need to check to make

sure certain classes exist before doing

anything with them. For example, older code

will often have the popover reference we

added in the detail view controller declared

as type “id” since you couldn’t assume

the UIPopoverController was a valid type

on iPhones. If you support old versions of

iOS, you’ll need to do the same. Apple has

excellent documentation on writing backward

compatible code that you should look into if

you’re going to support older versions of iOS.



migrating to iPad



iPad Cross

Let’s get the right brain working. Here are some

vocab words from

your firstPuzzle

iPad chapter.

Untitled



Header Info 1

Header Info 2

etc...



1

2

3

4



5



6

7



8



9

10



Across



Down



3. ___________ is what you're doing when you implement

code that differs by device

7. This control is iPad specific and controls other views.

9. These are not just big iphones

10. iPads need to support all ________.



1. This control is used only on iPad

2. Apps compiled for both iPhone and iPad are

4. The Split View Controller keeps track of ________ views

5. To implement the popover, you need to add a ________ to

the portrait view.

6. This covers UI for iPhone and iPad

8. The images display when the app is starting up



you are here 4   357

www.it-ebooks.info



iPad cross solution



iPad Cross Solution

Let’s get the right brain working. Here are some

vocab words from

your firstPuzzle

iPad chapter.

Untitled



Header Info 1

Header Info 2

etc...



1

2



U



3



D



E



V



I



C



E



C



H



E



C



K



I



N



O

G



P

4



I

5



6



B

7



U



S



P



T

O

N



L



I



T



V



A



T

10



8



H

I



E



W C



I



E



N



N



T



G

T



A



T



I



C



O



V



H



V



E



I



E



R



O



L



S

9



U

R



O



O



N



S



I



P



P



A



L



E



R



D

D



S



L



C

H



Across



Down



3. ___________ is what you're doing when you implement

code that differs by device [DEVICECHECKING]

7. This control is iPad specific and controls other views.

[SPLITVIEWCONTROLLER]

9. These are not just big iphones [IPADS]

10. iPads need to support all ________. [ORIENTATIONS]



1. This control is used only on iPad [POPOVER]

2. Apps compiled for both iPhone and iPad are [UNIVERSAL]

4. The Split View Controller keeps track of ________ views

[CHILD]

5. To implement the popover, you need to add a ________ to

the portrait view. [BUTTON]

6. This covers UI for iPhone and iPad [HIG]

8. The images display when the app is starting up [LAUNCH]



358   Chapter 7

www.it-ebooks.info



migrating to iPad



CHAPTER 7



Your iOS Development Toolbox

You’ve got Chapter 7 under your belt

and now you’ve added a bunch of iPad

controls to your toolbox.



iPad HIG



There are iPad-specific controls,

and some rules differ between

iPhone and iPad.

The Split View Controller and

popovers are iPad-specific controls.



Device Checking



Universal Apps



Depending on how you want to

distribute your app, you can

build two apps or a Universal

app. Universal apps are only sold

once, but they contain code for

both the iPhone and iPad, which

makes maintenance easier and the

customers happy!



Once you build a Universal app,

you’ll need to check for different

devices so your app can behave

differently as needed.



Split View Controller



This controller’s job is to ke

track of two child views th ep

displayed differently in portat are

and landscape. Once you set rait

up properly, you can have a it

number of views that displa small

y lots of

different ways.



you are here 4   359

www.it-ebooks.info



www.it-ebooks.info



8 tab bars and Core Data



Enterprise



Bounty hunter apps



Here’s what I ‘ve found: we

just can’t be competitive

anymore without an iPhone app!



Enterprise apps mean managing more data in different ways.

Companies large and small are a significant market for iPhone and iPad apps. A small

handheld device with a custom app can be huge for companies that have staff on the go.

Most of these apps are going to manage lots of data, and since iOS 3.0, there has been

built-in Core Data support. Working with that and another new controller—the tab bar

controller—we’re going to build an app for justice!



this is a new chapter   361



www.it-ebooks.info



bob’s on the go



HF bounty hunting

With my business, I’m out of the office a lot.

The courts will let me submit evidence from my iPhone

now, so I need an app for that to get paid. I picked

up an iPad while I was at it, since I figured it would

help me do more detailed research during boring

stakeouts. Can you help me with some apps for

both?



Bob needs some help.

Bounty hunting is not a desk job; Bob needs lots of

information to pick up fugitives on the go. His iPhone is

ideal to take along while he’s chasing bad guys, while his

iPad will great for more detailed background work. Here’s

what Bob needs in his apps:



Bob the bounty

hunter

1



iPhone App

1



2



 ob needs a list of fugitives. He

B

he’s

has to keep track of everyone

he’s

ple

peo

h

looking for, along wit

captured.

He wants to be able to quickly

ed

display a list of just the captur



2



3



fugitives.



3



 e also needs a display of the

H

h

detailed information about eac

ted

wan

y’re

the

at

wh

like

fugitive,

and

for, where they were last seen,

is.

nty

bou

ir

the

how much



362   Chapter 8

www.it-ebooks.info



iPad App



Details on past w

hereabouts.

They’ll have a lo

cation and details

about what the fu

gitive was doing

there.

For research, Bo

b needs the full

dossier on each

fugitive. Picture

and details shou

ld all be in the

same view.

 ll the informat

A

ion he uses in th

e

iPhone app, too.



tab bars and core data



Jim: OK, so he wants the entire package, iPhone and iPad.

Where do we start?

Frank: Well, we’re going to want to create another

universal app.

Joe: Right, then we can keep the logic and everything

together, just like we did last time, but with different views.



Jim



Jim: OK, so what do we do first?

Joe: What if we start with the iPad, write that, and then do

the iPhone, since it’s smaller?

Frank: Two things. First, we need to design everything.

Jim: Why?



Frank



Frank: Because we want to figure out what the two views

will have in common and make sure it’s set up right.

Jim: Oh.

Frank: Second, since the customer gets paid based on using

the iPhone app, pretty sure he’s going to want that first.



Joe



Joe: But it’s smaller! I think we should do the hardest one

first.

Frank: Listen, we work for Bob and this is what he wants.

Joe: OK, so the plan is...

Jim: We’ll start with designing both views, then code up the

iPhone and the backend together.

Frank: Right, then we can lay the iPad view on top.

Jim: OK, let’s get started.



you are here 4   363

www.it-ebooks.info



universal benefits



pps

Universal A

If you’re planning on supporting both devices from the beginning, it’s best to start

with an app set up to do just that. Remember, a universal app comes with all this

stuff built right in:

One binary file to maintain.

The files will compile together and support both devices. That means

that changes only need to be tracked once.

UIs will be separate.

Universal apps have two separate view controllers and Interface Builder

files, one each for the iPhone view and the iPad view.

Shared code needs device checking.

Since all of the logic code will be shared (if we do our job right), there’s

going to need to be more device checking than before. Instead of just 4

generations of iPhones and iPod Touches, you’ll also need to watch out

for iPad-specific stuff.

Universal apps are sold once, used twice.

The way the App Store is set up, universal apps are sold as an app

that will run on both devices. Users buy the app, put it in their iTunes

libraries, and then those who have iPhones and iPads can install it on

both as a native app. It may look and act differently, like iBountyHunter

will, but you only get paid once.



It’s something to consider. The iPad app

store is full of XD and XL versions of

apps that you can charge for again.



Now for some UI work...

364   Chapter 8

www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 7. Migrating to iPad: We need more room

Tải bản đầy đủ ngay(0 tr)

×