iPhone 5 Optimisation - iphone

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.

Related

When iPhone6 back to foreground, the view is getting small

I get a project from my friends and it is about cam. And In iPhone 6 when I open a view, touch Home button,back to the app, the app is no more full screen.I don't know why? the iPhone5 is work well.
Please help me! many thanks.
this is not a issue, you did not set compatibility with screens. because i-phone 6 has larger screen size(375*667) than i-phone 5 screen size(320*567). therefore you have to apply checks of compatibility.
CGRect screenSize;
screenSize = [[UIScreen mainScreen]bounds];
NSLog(#"%f",screenSize.size.height);
float height = screenSize.size.height;
if (height == 667)//this is i-phone 6 height
{
//change your view frame here, set according to i-phone 6 screen bounds
}

How to convert from iPAD/iPAD2 layout to iPhone4/iPhone5/iPAD-mini layout

I never used Interface Builder ever in my app, and don't think it is something good to do.
My app was already designed for iPad/iPad2 layout, without ever considering making it work on iPhone4/iPhone5/iPAD-mini. Now I want my app to work on all of them.
I think it would be extremely ugly to have 4+ layout the universal app, like this:
if(ipad or ipad2)
view.frame = CGRectMake(0,0,100,100);
else if(ipad-mini)
view.frame = CGRectMake(0,0,100,100);
else if(iphone4)
view.frame = CGRectMake(0,0,100,100);
else if(iphone5)
view.frame = CGRectMake(0,0,100,100);
else if(iphone6)
view.frame = CGRectMake(0,0,100,100);
else if(iphone7)
view.frame = CGRectMake(0,0,100,100);
There should be only 2 layout ideally, but I don't know how to implement this way. Those fixed coordinates would not stretch on different screen sizes
if(ipad or ipad2 or ipad-mini)
view.frame = CGRectMake(0,0,100,100);
else if(iphone4 or iphone5 or iphone6 or iphone7)
view.frame = CGRectMake(0,0,100,100);
How do I do a universal app in the best way?
when you started building this app you should have done soemthing like this:
view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
and you change above options according to your needs.
and yes you would need different for ipad, iphone
First of all, your layout for iPhone will almost certainly be drastically different from iPad. For the iPads, all the different types have the same aspect ratio, so all you need to worry about is having the #2x images for the iPad with retina.
For the iPhone, however, you have the iPhone 4/4s VS the iPhone 5. Also, you have a lot less screen space, so you will need to find ways to present the same information in a smaller space. This can be done using scrollviews, tableViews, and having one part of the information in one viewController that you can switch to from another viewController.
Finally, I would highly recommend interface builder for most cases. It takes care of iPhone vs iPhone 5, and portrait vs landscape for you. It will even automatically animate the transition when rotating the phone. Sometimes, however, when you need to do custom drawing or our layout is really hard to get with interface builder, it is better to do it programmatically. In that case, a good way to check which device would be by checking the size of [[UIScreen mainScreen] applicationFrame]. Check that with the values of 1024x768 for an iPad, 320x480 for iPhone, or 320x568 for iPhone 5.
However, you really should use interface builder (for most cases). Why exactly do you want to avoid it?

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 :)

Button with background image - iPhone 5 resize issue

I have been looking everywhere on here and Google, but I still have this weird issue that I can't figure. I have an app pictures below, with 4 UIButtons that have a background image applied:
When I resize/run on the iPhone 5, the top button resizes in a very strange way:
How do I get all the UIButtons to resize the same way with the iPhone 5? Is it possible? Do I need to use a different method?
I really hope this is not a duplicate, but I am completely stumped. If I change the UIButtons around in other positions along the UIView, a different one will resize, or strange gap spacing will show up.... I don't understand. Thanks for any help!
EDIT: I am using iOS 6 on Xcode 4.5. I am testing on an iPhone 4S and an iPhone 5. I have AutoLayout checked. If I use Pin (just found it) I can get the UIButton to keep its height.
To clarify my question. I want the UIButtons to resize so they occupy the same percentage of the screen.... I want the proportions to be the same, instead of simply adding a bunch of empty space. I hope that make it more clear
One of the features you can use is called AutoLayout. Its provided with Xcode to make it easier adjusting things for the 4 inch screen. You can find a good example here: http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
But as far as I know AutoLayout works only with iOS 6 which makes it "not so useful yet". I have been using a class called UIDevice, source of which can be found here: https://github.com/erica/uidevice-extension and check if the platform type is iPhone 5. I have it set up in a method which setups GUI when the view loads. Example of my implementation:
UIImage *backgroundImage;
if ([[UIDevice currentDevice] platformType] == UIDevice5iPhone)
{
//I have a 4 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 5
backgroundImage = [[UIImage alloc] initWithCGImage:[UIImage imageNamed:#"main_background-568h#2x"].CGImage scale:2.0 orientation:UIImageOrientationUp];
}
else
{
//I have a 3.5 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 3, 3gs, 4, 4s...
backgroundImage = [[UIImage imageNamed:#"main_background"] retain];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
[backgroundImage release];
Hope it clears a bit.
you should firstly disable the use AutoLayout this option is under the "Show the file inspector"

How to migrate apps for iPhone 5 screen resolution?

I have an application in iphone in which i am using most of the static images in the background as an image in the background image it self.Means a single background image including all the staic things.now i want to migrate to iphone 5 also.Now i am using an image of 640*960 as the background image.if i change that to 640*1136 then when it used in 4serieses of iphone the image will shrink i think.Let it i am fixing the frame size by checking the screeen.Can anybody help me how i can resolve this issue?
To know, what kind of image You should use (for iPad 768x1024, for iPhone 320x480, etc..)
You can detect device, and then set corresponding image.
You can distinguish between iPad/Retina/iPhone using this SO article:
Detect retina screen/iPhone 4 in iPhone SDK
You can detect iPhone 5 using example in this SO article:
How to detect iPhone 5 (widescreen devices)?
If you have only portrait supported, You can check using this simple method:
if([[UIScreen mainScreen] bounds].size.height == 480)
{
//iPhone, iPhone retina
}
else if([[UIScreen mainScreen] bounds].size.height == 1024)
{
//iPad, iPad retina
}
else //568 height
{
//iPhone 5
}
And of course - as Valeriy Van mentioned, You need Default-568h#2x.png image added to your bundle.
There is no connection between image resolution and size of UIImageView. Image will be rescaled or positioned inside view bounds depending on contentMode property.
What you need first - add Default-568h#2x.png image of 640x1136 as Launch Image for Retina 4 inch. If springs and struts of your views are set right, everything will work as granted.