Extend app for iPhone 5 - best practice - iphone

Now that Apple is about to start shipping iPhone 5's, I'm looking into extending my applications so they appear full screen on the iPhone 5. I ran my apps on the simulator, and even the ones with a UITableView extending to the bottom of the screen, the black bars appear at the top and bottom of the screen.
Here's my question: What is the best practice for extending apps for the iPhone 5?
Should I make a separate nib now for the 3.5 and 4 inch screen, or extend everything in code?
I'm trying to make this as smooth a transition as possible, so I appeal to knowledge of SO to clue me in onto what the best way is to build for both screens.

Taking advantage of the full 4" screen in your apps seems to be as simple as adding a new Default image named Default-568h#2x.png with size 640 x 1136. Xcode 4.5 will actually offer to do this for you automatically by adding a black image of the proper size and name to your project.
For apps that use standard UI components, such as table views, the tables are magically extended to fill the screen. I updated an app for work and it was literally this simple, with only a couple minor issues related to my own code and UI setup. But all in all, very easy.
Contrast this with another app I work on (for myself), which uses none of the standard UI components except for UIViews. To deal with both 3.5" and 4" screens, I have had to spend quite a bit of time refactoring code that needs to know screen size for various operations of the app. (The app in this case is more of a game/simulator than say, a productivity app.)
So, your mileage may vary with regard to the level of effort really required to support the 4" screen. It will depend on how complicated and "non-standard" your app is, as I have discovered.

When updating an existing app for the larger-screen iphone 5, you may also find that the bottom of the screen is not "clickable". For example, if you have a toolbar along the bottom of the screen, that toolbar would be displayed correctly, but buttons would not react to the touch. If this is the case, you need to tell the app that the window is using full screen.
If you have MainWindow.xib, open it, select the window and in the attributes inspector make sure that "Full Screen at Launch" is checked.
If you don't have MainWindow.xib in your project (and most newer projects don't), then you need to add one extra line in the applicationDidFinishLaunching of your app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window setFrame:[[UIScreen mainScreen] bounds]];
...
}
I put it in the beginning of the method. Worked like a charm.

You will find this path with simulator XCode->Targets->Summary->iPhone/iPod Deployment Info( the Retina 4-inch )
You need to add a Default image with size 640 x 1136.
Apply this code in your AppDelegate file
mainWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
mainWindow.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
You will get the main screen size of your window. one more thing whenever you want to check in your class file just add this code
if ([UIScreen mainScreen].bounds.size.height > 500.0f)
For your view controller just add one property autoresizingMask
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
This works fine for me.

I was looking for the same issue, trying to get iPhone 5 (4") to render my xib files to full screen, and I found this answer, which says you only need to add the Default-568h#2x.png image to tell the iOS that it needs to render your app in 4" fullscreen. just adding this fixed the problem for me.
Why [UIScreen mainScreen].bounds] is not returning full screen size?

Related

Subviews incorrect size?

Let me start off with saying that I am no expert in iOS Development or Objective-C.
I am making a app for a local charity(its a church) and they want it to support rotation.
The app work as expected if started in portrait mode, I can choose my new subview and the rotate it works perfectly.
However I need it to work so they can rotate at any time. The Main view(the one loaded on startup) already does this out of the box; but my subviews do not.
I have attached 3 screenshots below to try and explain what I mean.
This is how it looks in portrait mode:
In landscape:
and back to portrait it I started the app rotated:
If it helps I add the subview like this:
dailyPrayerView = [[DailyPrayerView alloc] initWithNibName:#"DailyPrayerView" bundle:nil];
[self.view addSubview:dailyPrayerView.view];
Does anybody have any ideas why this is?
Check the autoresizing mask in Interface Builder. It's on the sizes pane of the Utilities pane. You should be able to make it stretch to fit the screen, rather than staying at a constant size.

Making a UIView landscape

I have created an iPhone app, which is a tab bar application and only in portrait orientation.
From one tab I am presenting a modal view which contain UIImage view.
Can I make landscape orientation only to that view while rotating iPhone to 90 degree?
yes , you can.
There are a few settings, code part which need to make it.
Depends also for which version, hopefully aren't targeting all supported by xcode, because it is horrible. Better choose only one, like the lastest iOS.

Camera Overlay height for both iphone 4 and iphone 5

I'm using the standard UIImagePickerController and using a camera overlay view with it, default controls. I've got an external nib file which I load the overlay view from. The problem is that the view seems to be at 460, so doesn't fully encompass the camera view on iphone 5. I'd like to approach this using auto layout, but I'm not sure how to tell the nib to adjust it's size to be either a height for iphone 4 or iphone 5.
I thought about using setFrame, but that's very un-auto layout. I've also thought about having 2 different nib files, one for iphone 4 and one for iphone 5, but that seems to be the wrong approach too. I'm guessing there's some way to tell the nib to fill the current camera view, but I'm not sure what it is. Can someone recommend the "correct" way to handle this?
You can programmatically load a different cameraOverlayView XIB based on the phone dimensions. The camera controls strip is about 54px tall on 480h screens, and about 96px tall on 568h screens.
Alternatively, you can certainly design your XIB with auto resizing masks set appropriately, but will need to then do a setFrame in code to get the right dimensions.
So either way, you're writing some code to detect the screen bounds and either loading a different XIB or doing a setFrame.
I haven't used nibs for a while now (preferred storyboard) but I believe what you have so far is a UIImageView in the nib, right? Make that an outlet. And then in your m file, check for dimension of the device (many people have asked this recently how to check screen dimension), then you set the uiimageview frame based on the found dimensions. It should work ;)

Adding a viewController as subView programmatically

I am building an Iphone app.
I need to display a settings Menu to the user when a button is clicked. The menu will NOT be covering the whole screen and there is a specific location I want it to appear. How should I do that?
I understand how to set the hidden property of a subview to give the illusion that the subview is not onScreen. However, I need a view controller for this subview ( meaning .m and .h files as well). So How can I add this subview programmatically at a specific location.
Thank you very much
What you are describing is very much the behavior of a UIPopoverController. Unfortunately, that is only available for use on iPad's and not iPhone's or iPod Touches. So if you want to develop this you will need to develop this from scratch.
It's not a UI pattern you see much on the iPhone due to the screen size, but I imagine you will need to build up a custom UIView and add it the main window view with a specific size (smaller than screen size) and with the view's frame.origin set to a value other than (0,0).
Just make sure that what you are trying to achieve falls within Apple's Human Interface Guidelines.
[myView addSubview:myViewController.view];
myViewController.view.frame=...

Struggling with making my app displaying properly on iPad

I have a little trouble grasping the concept of making views that will display proper on iPhone, iPhone 3G(s), iPhone 4 and iPad.
Lets say I have regular UIImageButton at a position of (200, 300), and size is (100, 60).
If I define those values in CGRect structure the button will scale properly on iPhone depending on whether or not it is with iPhone (320px, 480px) or iPhone 4 (640px, 960px). I only need to provide a extra set of images with the doubled size since I am not specifying real pixels but points.
However on iPad this does not work, or else I am doing something wrong because it does not display properly.
I want to know if there is possible to specify that the imagebutton in this example would stay at the same location as on iPhone. I also need to know how I should "properly" initialize a e.g. UIImageButton. Is it correct to say
[[UIImageButton alloc]
initWithFrame:CGRectMake(200.0f,
300.0f, 100.0f, 60.0f)];
if I want to have it located on the same location on the iPad version. Could anyone explain? Thanks in advance.
It's easier to do this in Interface Builder. Select the view, and in the Inspector click on the tab with the ruler (third tab in). The "Autosizing" section lets you control how the location and size of the view changes depending on the device and orientation.
To do this in code, you change the autoresizingMask property of the UIView, e.g.
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight