1 to 1.15 Scaling from iphone to ipad and phone5

Discussion in 'iPhone/iPad Programming' started by IDMah, Dec 2, 2012.

  1. macrumors regular

    Joined:
    May 13, 2011
    #1
    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
     
  2. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    I'm confused. What are you trying to do and what are you getting?
     
  3. macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3
    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.
     
  4. thread starter macrumors regular

    Joined:
    May 13, 2011
    #4
    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
     
  5. macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #5

    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,
     
  6. macrumors 603

    Joined:
    Apr 15, 2004
    #6
    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.
     

Share This Page