Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode 4.5, iPhone 5 breaks my UIScrollView

So I've got a pretty complex project. I'm using both interface builder and xcode directly to build objects. Right now I have UIScrollViews being built in IB, where they need to be, and UIButtons built on top of those scrollviews. There are several scrollviews in the same spot, but that really shouldn't make much of a difference.

Anyway, the issue is that it works perfectly on the iPhone 4. But when building on the iPhone 5, it moves the Scrollviews to the bottom of the screen, where before it was x=0, y=361. All my other objects are being placed correctly with some empty space underneath them. I know how to check for iPhone 5:

I don't know how to post code on here with colors and whatnot, they make it super complicated so here is how I'll do the if/then:

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480){
            // iPhone Classic
        }
        if(result.height == 568){
            // iPhone 5
        }
    }

I don't know of a way to do if/then in IB. I tried just manually changing the location this way:

[peopleScrollView scrollRectToVisible:CGRectMake(0, 449, 320, 58) animated:NO];

That did not work. So, what I'm asking is there a way to change the location of a UIScrollView in the code itself? If there is not, then I think I will have to build all 5 UIScrollViews manually in code, which I definitely do not want to do.

like image 696
Jeff Stone Avatar asked Sep 28 '12 18:09

Jeff Stone


1 Answers

If you select your Scroll View object, then click the Size Inspector module, you will notice the default Autosize Mask is set to: Left, Top.

Left-Top Autosize / Offset Mask

Depending on your view "Mode" option, and your view's "Resize Subviews Automatically" option, this view and subviews will be shifted down on the 4" screen compared to the 3.5" screen.

Depending on what your particular view should look on each screen is up to you. On my project, I adjust the autosize mask to Left, Top, and Bottom,

Left-Top-Bottom Automask / Offsetas I want my UIScrollView and subviews to remain at the top of the screen (as drawn in IB) on the 3.5" and 4".

You can also set vertical and / or horizontal sizing arrows inside the box in the autosize graphic

Vertical and Horizontal Autosize Mask. This will attempt to scale object as accordingly for dynamically sized screens.

The Autosize Mask should be your new best friend with iPhone5.

See Xcode Interface Builder. How Do These Autosizing Mask Settings Differ? for more info.

like image 64
NathanChristie Avatar answered Jan 01 '23 22:01

NathanChristie