Convert iphone 4 app into iphone 5 - iphone

We have update our application to support both iPhone 4 and iPhone 5 screen size. It is working fine in both simulators but when we install it on iPhone 5 device then it behaves like iphone 4 application (Black borders on top and bottom). We have also added Default-568h#2x.png bot not working correctly. We are creating window dynamically.
What we are missing here ? Any ideas ?
Also how to set "Full Screen At Launch" property of UIWindow programmatically ?

Here is one solution that worked
A. In your AppDelegate.m initialize the UIWindow object like this
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
B. In order to manage other UI Elements You can define a macro that provides current frame of the screen be it iPhone 4/iPhone 5
#define SCREEN_FRAME [[UIScreen mainScreen] applicationFrame]
Accordingly you can use SCREEN_FRAME width/height properties to adjust other UI elements
Hope this helps.

Related

Making application compatible with iPhone4 and iPhone5 without setting diffrent frame size

Today i am going to create an iphone application which is compatible with iphone4 and iphone5. Earlier i have changed iphone4 application views programetically by using below code to adjust controllers for iphone5.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for iphone5
}
else {
// code for iphone4
}
am thinking this is difficult to track all the frames and sizes of controllers each and every time. I have created one sample app and also tried with Auto-resizing option(i have put check mark) at the starting of view and selected size Retina 4 full screen in inspector. And also selected simulator hardware-device is iphone Retina-4 inch
if i change simulator hardware-device is iphone Retina-3.5 inch then the screen is looking like
My question is without setting frames how can i achieve this problem.
Please help me.
Thanks in advance.
You can use this link for autosizing
http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/
Instead of giving static numbers give frames dynamically. means instead of giving 320 give self.view.frame.size.width so you no need to check the device, just you need to add default splash screen.
You problem could be resolved easily using Autolayout feature provided in the XCode Version 4.x .
Go through the following link :-
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
By applying few contraints using Autolayout your problem could easily be resolved.
Happy Coding :)

iPhone 5 Optimisation

I'm super confused about how the iPhone 4 and below apps are optimised for the iPhone 5. I'm a designer. How is optimisation done? Basically I have an app with loads of knobs and buttons and other interactive components. The way I see it, there are 3 options but what is the best way (or least, standard practice)?
1) Keep the layout the same for iPhone 5 but just add extra length on the background.
2) Scale the images/layout of components from iPhone 4 to iPhone 5 so everything is proportional.
3) Have completely separate images and different layouts for both. i.e for iPhone 5, I can move components to utilise the space more. The problem with this (and I'm not a developer) is that the interaction position of the components have moved so in effect, the iPhone 4 and 5 are separate apps?
To identify if it is a iphone 5 iphone, use this code in the file nameYourApp-prefix.pch:
//Macro iPhone5
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
find the nameYourApp-prefix.pch file in the supporting files, the code must be written between:
# ifdef __ OBJC__
//Code Macro iPhone5
# endif
and then just use the "if" to check that device, like this:
if (IS_IPHONE_5) {
//Code for 4 inch screen
}else{
//Code for 3.5 inch screen
}
putting the macro in the nameYourApp-prefix.pch, all classes see it.
With a UIKit application, none of your options are ideal. You simply use Springs and Struts or Auto Layout to have your user interface elements snap to where they should be.
The solution is the same when switching between portrait and landscape orientation. You define which user interface elements can grow and which ones can't, which edges to snap to, etc.
Run it on the simulator to test the layout if you don't have an iPhone 5 device.
For example, for a UITableViewController, the UITableView should grow vertically on an iPhone 5 so that you see more rows.
I almost always have at least one control that would be nice to grow given the room. If you don't, then you'll probably just have more empty space at the bottom of the view.
How iPhone 5 Optimization Works
When you tell iOS that your app is optimized for the iPhone 5 (through use of a cleverly named image file), iOS uses your existing Springs and Struts or Auto Layout (whatever you're using) to rearrange the interface.
The first choice is the easiest and works pretty well. You'd only need to worry about having specific assets for full screen images, and make sure that NavigationBar and TabBar (in case your app have one), remains on top and bottom respectively.
Scaling other images/components such as buttons, you'll change the general aspect ratio (which you probably wouldn't want), since iPhone 4&5 display sizes only differ in height.
For developing app option two is better. Although you dont have to change all the images for iPhone 5 some images will me same like TabBarItem. But you have to create background image different for iPhone4 and 5.
Read out this apple document to create user interface.
And you can differentiate iPhone 4 from iPhone 5 using this code
UIBtton * btn = [[UIButton alloc] init];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
btn.frame = CGRectMake(60,60, 205, 175);
//this is for iPhone5
}
else
{
btn.frame = CGRectMake(60,50, 199, 170);
//this is for iPhone4
}
Here my button place and length are different for iPhone 5 and iPhone 4
And set your control's hight and width according to iPhone Screen Size.
If you didn't, adjust your view layouts with proper auto resizing masks or look into Auto Layout if you only want to support iOS 6 going forward. You have to check height of [[UIScreen mainScreen] bounds].
Example:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen (iPhone 5)
} else {
// code for 3.5-inch screen (< iPhone 5)
}
Note that [UIImage imageNamed:#"yourImage.png"] will only load either "background.png" or "yourImage#2x.png", it will not load "yourImage-568h#2x.png" if it exists.
Check Auto-Rotation API as Well.

iPhone 5 UITableView

I am trying to update my App for the iPhone 5's larger screen real estate. I have a tableview that has expanded to take up the full height of the screen by adding the Default-568h#2x.png to my project, but the bottom couple of cells are not responding to touched in the simulator or the actual iPhone 5. Am I missing something? It's like the bottom portion of the screen is not detecting touched (but just in my App not the others).
Any thoughts?
Thanks,
Rob
This is whats working for me
In application didFinishLaunching method I added this -
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
In any other view controller, preferably in - (void)viewDidLoad;
UIScreen *screen = [UIScreen mainScreen];
[self.view setFrame:[screen applicationFrame]];
Yes may be your window frame size in AppDel class or in XIB file of your project's appdel class is not as per iPhone 5 Screen.
And change window frame according 3.5 inch and 4 inch screen of iPhone

Best way for creating universal native iPhone/iPad application?

Which approach is good to create universal native application for iPhone/iPad:
1) Create separate NIB files for iphone and iPad versions and load the specific version by checking (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad).
2) Get the dimension of the main screen and frame the view accordingly
CGRect mainWindow = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, mainWindow.size.width, mainWindow.size.height)];
Please suggest if any other approach that I missed
Thanks,
Ajay
I am using the first approach, in many cases, at least for my own it is sufficient to set autoresizing masks. You have not said anything about this, but if your application will look pretty much the same (up-scaled layout) this works fine. In the cases I need another layout I have checked whether it is an iPad/iPhone and loaded the correct NIB, or used the GUI code in loadView based on the device.
From you example code with the webview you could use autoresizing masks and it would resize to the correct proportions when the frame changes.

How to set brigtness of ipad or iphone by programming?

I have implementing pdf application for ipad.Now i want to set brightness in my application.Is it possible?Please help me for this problem.
Thanks in advance.
Most applications that you see with this feature are putting up a full screen solid black view or window and adjusting the alpha level. The brightness is then adjusted from some minimum value to the current system maximum. The actual system brightness cannot be accessed by a sandboxed application.
UIWindow *shader = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds];
shader.backgroundColor = [UIColor blackColor];
shader.alpha = 0.1;
With a view, you have the option of being behind things like toolbars. With a window, you can be over everything if you set the window level high enough. Do not let the alpha level go above 0.5 or whatever you choose as your limit.
short answer: you can't in the official sdk.