Autosizing in IB

Discussion in 'iOS Programming' started by iLoveDeveloping, Mar 29, 2010.

  1. iLoveDeveloping macrumors 6502

    Sep 24, 2009

    I there any more advanced way of autosizing in IB? I have a few views that i want to rotate to landscape but every configuration i have tried just doesn't the the results i need!

    Is there any way to tell it, i want this (picture) in this position in portrait but this position in landscape manually?
  2. DerekK19 macrumors newbie

    Mar 30, 2010
    Auckland, New Zealand

    Hi ILoveDeveloping.

    I'm a newbie myself so don't know if I can help you much. I'm on my first iPhone app and have only had my mac for 2 weeks! I saw your posting about rotating the view and I guess this is where you're coming from. I saw an obvious error in your last but one posting on that thread, which started a flame war that didn't help you. It seems your mistake was to have two "return" statements one after the other. So the function returns after the first one, and doesn't therefore execute the second. I think you mixed up the ideas of "if" and "return" - hence the go back and read your Objective-C primer comments. Of course I'm an Obj-C newbie, so my advice is to be taken with a pinch of salt.

    I'm trying to do exactly like you. My view rotates - that's simple. But since my view is like a set of text boxes below each other, when I rotate some drop off the bottom of the screen and there's a load of blank space to the right. Clearly the answer is to have a different view when in portrait from the landscape view. I don't think this can be done by autosizing. In fact my app is like a recipe card - a picture with some text below it. when I rotate I want the text on the left and the picture on the right. I don't see how that can be done with one view - or if it can, then IB is way cleverer than I'd have imagined.

    If you got your "different views" code working that's probably where you have to look next. I have not worked out how to have two different views depending on the orientation, but I'm certain that's the key - I haven't yet found a need for autosizing, though on the PC (which I have stacks of experience with) it generally means if I widen the window the text boxes in the window will widen too. Look at this "reply to post" page, when I widen the Safari window, the "Additional Options" boxes below this area also widen. To me that's autosizing. I don't know if you'd really use autosizing on the iPhone - since the "window" size is fixed. Again, be ready with that pinch of salt - I'm a newbie remember; what do I know?.

    I try to be patient when people bring problems to me (and hope for the same in return). If I was abusive to any of my team at work I know I'd lose their respect, and I would not get the best out of them. Sure they make mistakes, we all do, and sometimes they're stupid ones. The art is showing the way without putting someone down.

    I'd like to know more about how you changed views when you rotated. I'm going to Google more on that, but again I'm sure that's the key.
  3. DerekK19 macrumors newbie

    Mar 30, 2010
    Auckland, New Zealand
    I may have spoken too soon

    Of course autosizing is relevant, because if you rotate the device, the "window" size changes and so the controls in the window can be resized or repositioned.

    I found this chapter on Google books in Beginning iPhone 3.0 development. It explains autoresizing and (for me) using multiple views. I may look at getting the book, it looks very useful.

  4. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    The more-advanced method of autosizing is to use a container view and implement layoutSubviews in that view. Your layoutSubviews method will adjust the size and positions of its subviews in code however you'd like.

Share This Page