Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
Hi all.

I can determine the screen Size by:
Code:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([UIScreen mainScreen].scale == 2.0f) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);
            
            scalerX=1;
            scalerY=1;
            
            NSLog(@"Screen is X:%f Y:%f",scalerX,scalerY);
            
            if(result.height == 960){
                NSLog(@"iPhone 4, 4s Retina Resolution");
                             
            }
            if(result.height == 1136){
                NSLog(@"iPhone 5 Resolution");
                             }
        } else {
            NSLog(@"iPhone Standard Resolution");
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);
            
            scalerX=1;
            scalerY=1;
            
            NSLog(@"Screen is X:%f Y:%f",scalerX,scalerY);
            
        }
    } else {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width * scale, result.height * scale);
        
        if ([UIScreen mainScreen].scale == 2.0f) {
            NSLog(@"iPad Retina Resolution");
         } else{
            NSLog(@"iPad Standard Resolution");
                       
        }
        scalerX=2.0; <--- why does this work better ??
        scalerY=2.0;
 
       // tried ratio of 326/163 which is 2 anyway.
 
        NSLog(@"Screen is X:%f Y:%f",scalerX,scalerY);
        
       
    }

but maybe because I eyeballed the placement of the Bitmaps
if I multiply the currentX * scalerX it's off also

tried
Code:
positionX =currentX * scalerX 
// also tried this .. both are off for ipad //
positionX = currentX*(result.width/320);

What am I doing wrong? Is the original iphone resolution not 320 X 480??
what should I scale by??

thanks
Ian
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Hi all.

I can determine the screen Size by:
Code:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([UIScreen mainScreen].scale == 2.0f) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);
            
            scalerX=1;
            scalerY=1;
            
            NSLog(@"Screen is X:%f Y:%f",scalerX,scalerY);
            
            if(result.height == 960){
                NSLog(@"iPhone 4, 4s Retina Resolution");
                             
            }
            if(result.height == 1136){
                NSLog(@"iPhone 5 Resolution");
                             }
        } else {
            NSLog(@"iPhone Standard Resolution");
            CGSize result = [[UIScreen mainScreen] bounds].size;
            CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);
            
            scalerX=1;
            scalerY=1;
            
            NSLog(@"Screen is X:%f Y:%f",scalerX,scalerY);
            
        }
    } else {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width * scale, result.height * scale);
        
        if ([UIScreen mainScreen].scale == 2.0f) {
            NSLog(@"iPad Retina Resolution");
         } else{
            NSLog(@"iPad Standard Resolution");
                       
        }
        scalerX=2.0; <--- why does this work better ??
        scalerY=2.0;
 
       // tried ratio of 326/163 which is 2 anyway.
 
        NSLog(@"Screen is X:%f Y:%f",scalerX,scalerY);
        
       
    }

but maybe because I eyeballed the placement of the Bitmaps
if I multiply the currentX * scalerX it's off also

tried
Code:
positionX =currentX * scalerX 
// also tried this .. both are off for ipad //
positionX = currentX*(result.width/320);

What am I doing wrong? Is the original iphone resolution not 320 X 480??
what should I scale by??

thanks
Ian

iPhone, iPad, and iPhone 5 all have different aspect ratios. There is no scale factor that will map layouts to all those devices without distorting it.

iPhone = 320:480 = .6666
iPad = 768:1024 = .7500
iPhone 5 = 320:580 = .5517

The iPad screen is also so much bigger than the iPhone screen that the same layout doesn't usually work. You generally need to rethink your forms design for the iPad, and put more functionality on one screen.

For example, in our company's location placemarking app, Save My Place, the iPhone version has a screen for the map view, a separate screen for the list of saved locations, and a third screen for the compass view. On the iPad version, all of that content fits quite nicely on a single screen.
 

IDMah

macrumors 6502
Original poster
May 13, 2011
316
11
Never an easy way out eh? hahaha !!!

Thanks all !!!

Was looking for an easy way out.. but because it was / is my first app.
I hard coded the positions. Guess I'm going to have to do it the painful way.

Reposition all the graphics by hand..

thanks again.. esp for the Ratios. should help scaling it at least.

thanks
Ian
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Thanks all !!!

Was looking for an easy way out.. but because it was / is my first app.
I hard coded the positions. Guess I'm going to have to do it the painful way.

Reposition all the graphics by hand..

thanks again.. esp for the Ratios. should help scaling it at least.

thanks
Ian


No, you should not reposition everything by hand.

You should not hard-code the positions of your views. You should use an XIB or storyboard. If you did that then you could use the "struts and springs" controls in interface builder to make your views adjust automatically to different view sizes and orientations. The idea is that you determine which edges stick to the sides of the containing view (struts), and which sides are allowed to float, and you tell each view if it should stay the same size or resize (springs). You can get pretty flexible resizing behavior that way, and it is a skill you should invest time in learning.

Note that iOS 6 includes a more sophisticated resizing system known as autoLayout, but that only works under iOS 6,
 

goMac

Contributor
Apr 15, 2004
7,662
1,694
Thanks all !!!

Was looking for an easy way out.. but because it was / is my first app.
I hard coded the positions. Guess I'm going to have to do it the painful way.

Don't do this. Write something that can position the graphics for any possible screen size.

You don't want to be screwed if Apple comes out with a new device at a different aspect ratio or resolution.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.