Layout on Mini is broken

  • Hi. I've got an iOS 6.1 iPad app that lays out fine in the iPad sim and on a Retina iPad device.

    On the Mini, however, it gets really wonky, sometimes. See here:

    http://cl.ly/image/2Q0p2z3x0D3S

    (I've crudely erased our giant logo from the center of the screen and our app name from the center of the top bar.)

    Sometimes, the top is okay, but the toolbar along the bottom is shifted upward about a toolbar width.

    The "215 MiB" is a separate view on top of the top toolbar. The icons on the left and right, and the title in the center, are UIBarButtonItem elements in the toolbar.

    Any idea what's going on?

    --
    Rick
  • On 4 Jun 2013, at 10:04 PM, Rick Mann <rmann...> wrote:

    > Hi. I've got an iOS 6.1 iPad app that lays out fine in the iPad sim and on a Retina iPad device.

    I'd wager the problem shows up on iPad 2 (which is still sold) as well. I'm going to simplify, and look only at the lower toolbar.

    # Some not-very-helpful research

    I'm going to concentrate on that lower toolbar, in hopes of simplifying the problem.

    This is all in the Simulator, and you've already said you don't have a problem there. I'm reporting my research to be thorough; and because I'm surprised that placement constraints don't appear in the .constraints arrays of both superview and subview.

    Skip this part.

    ## It behaves correctly in the Simulator.

    Using the simulator, hardware set to the non-Retina iPad, I don't see the bug. I took the single-view template, dropped a toolbar at the bottom (placing it inside the provided root view), verified that the vertical constraint was bottom space to superview (0), and inserted a flexible space to the left of the button the toolbar template includes. It behaved as expected when rotated.

    (I know you said the bug doesn't manifest in the simulator. I'm being thorough.)

    ## The toolbar has no placement constraints, but the superview does

    However: At -viewDidLoad time, neither the root view nor the toolbar had constraints. If I inspect the toolbar after sending the root view -layoutIfNeeded, or in an IBAction handler, it has only the vertical-size constraint. No vertical placement, no horizontal.

    But: The root view does have leading- trailing- and bottom-edge constraints on the toolbar. I thought constraints belonged to both views. Is that just a convenient conceit in Interface Builder?

    ## Autoresizing translation and .autoresizesSubviews don't change anything

    I set setTranslatesAutoresizingMaskIntoConstraints: to NO on both views. No change. I set .autoresizesSubviews to NO on the root view. No change. The toolbar laid out correctly, and it lacked constraints back to the root view.

    Switching the simulator to iPad (Retina) had no effect. Rotation had no effect. Layout always worked as expected.

    Obviously I don't know autolayout well enough.

    ---

    # Further questions

    > Sometimes, the top is okay, but the toolbar along the bottom is shifted upward about a toolbar width.
    >
    > The "215 MiB" is a separate view on top of the top toolbar. The icons on the left and right, and the title in the center, are UIBarButtonItem elements in the toolbar.

    Describe your particular case:

    * Where in the view hierarchy is the bottom toolbar placed?
    * What are its constraints as listed in Interface Builder?
    * What are they in the debugger (.constraints), for the toolbar, after layout has been forced?
    * For the superview?
    * Have you experimented with setTranslatesAutoresizingMaskIntoConstraints:?
    * With .autoresizesSubviews?

    — F

    --
    Fritz Anderson
    Xcode 4 Unleashed: 4.5 supplement for free!
    http://www.informit.com/store/xcode-4-unleashed-9780672333279
  • On Wed, Jun 5, 2013, at 07:10 AM, Fritz Anderson wrote:
    > On 4 Jun 2013, at 10:04 PM, Rick Mann <rmann...> wrote:
    >
    >> Hi. I've got an iOS 6.1 iPad app that lays out fine in the iPad sim and on a Retina iPad device.
    >
    > I'd wager the problem shows up on iPad 2 (which is still sold) as well.
    > I'm going to simplify, and look only at the lower toolbar.

    Fritz, I'm not sure what you're on about here. Did Rick share his code
    with you, and that's how you know he's using auto layout?

    --Kyle Sluder
  • On 5 Jun 2013, at 10:43 AM, Kyle Sluder <kyle...> wrote:

    > On Wed, Jun 5, 2013, at 07:10 AM, Fritz Anderson wrote:
    >> On 4 Jun 2013, at 10:04 PM, Rick Mann <rmann...> wrote:
    >>
    >>> Hi. I've got an iOS 6.1 iPad app that lays out fine in the iPad sim and on a Retina iPad device.
    >>
    >> I'd wager the problem shows up on iPad 2 (which is still sold) as well.
    >> I'm going to simplify, and look only at the lower toolbar.
    >
    > Fritz, I'm not sure what you're on about here. Did Rick share his code
    > with you, and that's how you know he's using auto layout?
    >
    > --Kyle Sluder
    >

    I inferred from the word "layout" in the subject line (thin, I admit), and from the screenshot he posted. I've seen issues like that with autolayout (when I've misapplied it), but never with autoresizing. And it's the default in the current templates.

    Or I'm just shooting my mouth off. I do that.

    — F

    --
    Fritz Anderson
    Xcode 4 Unleashed: 4.5 supplement for free!
    http://www.informit.com/store/xcode-4-unleashed-9780672333279
  • On Wed, Jun 5, 2013, at 10:43 AM, Fritz Anderson wrote:
    >
    > I inferred from the word "layout" in the subject line (thin, I admit),
    > and from the screenshot he posted. I've seen issues like that with
    > autolayout (when I've misapplied it), but never with autoresizing. And
    > it's the default in the current templates.

    Well it's certainly true that one cannot use auto layout to position or
    size controls within a UINavigationBar, but it doesn't sound like Rick
    is doing any of that; he's positioning a view above the navbar (in the
    z-order sense), and using standard bar button items around it.

    --Kyle Sluder
  • Thanks for the investigation, Fritz. Answers below.

    On Jun 5, 2013, at 07:10 , Fritz Anderson <fritza...> wrote:

    > * Where in the view hierarchy is the bottom toolbar placed?

    I've posted screenshots of the layout and hierarchy in IB:

    http://cl.ly/image/0X3e042b2939
    http://cl.ly/image/281F3w0a3U00

    > * What are its constraints as listed in Interface Builder?

    I don't think you can discern the constraints from the screenshots (IB constraints UI really needs an overhaul). I'm not sure how to concisely describe them.

    > * What are they in the debugger (.constraints), for the toolbar, after layout has been forced?
    > * For the superview?

    I'll get back to you.

    > * Have you experimented with setTranslatesAutoresizingMaskIntoConstraints:?
    > * With .autoresizesSubviews?

    I have not. The whole storyboard was created from scratch using autolayout, so I assumed that was set correctly and has never been touched.

    --
    Rick
  • On Jun 5, 2013, at 08:43 , Kyle Sluder <kyle...> wrote:

    > Fritz, I'm not sure what you're on about here. Did Rick share his code
    > with you, and that's how you know he's using auto layout?

    Fritz is right, this is all autolayout.

    --
    Rick
  • On Jun 5, 2013, at 10:51 , Kyle Sluder <kyle...> wrote:

    > Well it's certainly true that one cannot use auto layout to position or
    > size controls within a UINavigationBar, but it doesn't sound like Rick
    > is doing any of that; he's positioning a view above the navbar (in the
    > z-order sense), and using standard bar button items around it.

    This is also correct. The view above the nav bar is irrelevant (unless it's somehow causing the issue. Nope, just checked. Removed it, issue still occurs).

    Everything in this UI is pretty straightforward (I think; see the screenshots mentioned before). I haven't tried anything terribly fancy, with the exception of the center image (I still don't know how to get pinch zoom and rotation to work in the presence of constraints).

    --
    Rick
  • Here's some new news!

    I gave the iPad I'd been using to a colleague, got him set up building the app and running it on that iPad. He sees the same layout problem I saw on the iPad mini, but never on that iPad. So, it's not restricted to the iPad Mini.

    Argh.

    --
    Rick

    On Jun 5, 2013, at 13:56 , Rick Mann <rmann...> wrote:

    >
    > On Jun 5, 2013, at 10:51 , Kyle Sluder <kyle...> wrote:
    >
    >> Well it's certainly true that one cannot use auto layout to position or
    >> size controls within a UINavigationBar, but it doesn't sound like Rick
    >> is doing any of that; he's positioning a view above the navbar (in the
    >> z-order sense), and using standard bar button items around it.
    >
    > This is also correct. The view above the nav bar is irrelevant (unless it's somehow causing the issue. Nope, just checked. Removed it, issue still occurs).
    >
    > Everything in this UI is pretty straightforward (I think; see the screenshots mentioned before). I haven't tried anything terribly fancy, with the exception of the center image (I still don't know how to get pinch zoom and rotation to work in the presence of constraints).
    >
    >
    > --
    > Rick
  • After using the amazing Reveal app, I got this screenshot of my hieararchy:

    http://cl.ly/image/2I0P1Y370S0B

    It doesn't show constraints, AFAICT, so I'm still having to manually inspect each one (something IB really sucks at), and trying to see if there's an obvious incorrect one. But you can see from the screenshot that the top toolbar is being forced to grow larger vertically, and so the buttons are staying in the center, but the background image doesn't grow.

    On Jun 6, 2013, at 16:42 , Rick Mann <rmann...> wrote:

    > Here's some new news!
    >
    > I gave the iPad I'd been using to a colleague, got him set up building the app and running it on that iPad. He sees the same layout problem I saw on the iPad mini, but never on that iPad. So, it's not restricted to the iPad Mini.
    >
    > Argh.
    >
    > --
    > Rick
    >
    > On Jun 5, 2013, at 13:56 , Rick Mann <rmann...> wrote:
    >
    >>
    >> On Jun 5, 2013, at 10:51 , Kyle Sluder <kyle...> wrote:
    >>
    >>> Well it's certainly true that one cannot use auto layout to position or
    >>> size controls within a UINavigationBar, but it doesn't sound like Rick
    >>> is doing any of that; he's positioning a view above the navbar (in the
    >>> z-order sense), and using standard bar button items around it.
    >>
    >> This is also correct. The view above the nav bar is irrelevant (unless it's somehow causing the issue. Nope, just checked. Removed it, issue still occurs).
    >>
    >> Everything in this UI is pretty straightforward (I think; see the screenshots mentioned before). I haven't tried anything terribly fancy, with the exception of the center image (I still don't know how to get pinch zoom and rotation to work in the presence of constraints).
    >>
    >>
    >> --
    >> Rick


    --
    Rick
  • On Thu, Jun 6, 2013, at 06:10 PM, Rick Mann wrote:
    > After using the amazing Reveal app, I got this screenshot of my
    > hieararchy:
    >
    > http://cl.ly/image/2I0P1Y370S0B
    >
    > It doesn't show constraints, AFAICT, so I'm still having to manually
    > inspect each one (something IB really sucks at), and trying to see if
    > there's an obvious incorrect one. But you can see from the screenshot
    > that the top toolbar is being forced to grow larger vertically, and so
    > the buttons are staying in the center, but the background image doesn't
    > grow.

    Ok, so it looks to me like the constraint system within your content
    area is screwing up the layout for your entire window. So it's probably
    related to your pinch/zoom troubles from the other thread.

    Care to describe the view hierarchy and constraint system in your
    content area?

    --Kyle Sluder
  • On Jun 6, 2013, at 18:23 , Kyle Sluder <kyle...> wrote:

    > Ok, so it looks to me like the constraint system within your content
    > area is screwing up the layout for your entire window. So it's probably
    > related to your pinch/zoom troubles from the other thread.
    >
    > Care to describe the view hierarchy and constraint system in your
    > content area?

    As  best as I can:

    I removed all the pinch/rotation gesture stuff. It wasn't working, so I gave up (for now).

    Here's a screenshot of the constraints:

    http://cl.ly/image/3Y3S3r1x0p1c

    With few exceptions, they're all "equal to 0" constraints (the exceptions are the ones around the LZFreeMemoryView). They're all priority 1000. All the hugging priorities are 250, compression resistance 750.

    The Minimap Placeholder is the logo you see in the center. It's behind the UIScrollView. It's nicely constrained to center in the main view (BaseView).

    The Minimap is a UIImageView contained in the UIScrollView. It's over-constrained. I wanted it to center in the scroll view, but as I think about it, I don't know what constraints, if any are appropriate for the contents of a UIScrollView. As you can see, all of those are not user constraints, so I can't delete them.

    If you have any other questions, please ask.

    --
    Rick
  • On Jun 6, 2013, at 18:23 , Kyle Sluder <kyle...> wrote:

    > Ok, so it looks to me like the constraint system within your content
    > area is screwing up the layout for your entire window. So it's probably
    > related to your pinch/zoom troubles from the other thread.
    >
    > Care to describe the view hierarchy and constraint system in your
    > content area?

    I agree, by the way, that it's something about the autolayout constraints. It ping-pongs between affecting the top toolbar and the bottom one from one run to the next (randomly).

    I really don't understand why IB allows the minimap placeholder UIImageView to have only centering constraints, but requires the minimap UIImageView to have not only centering constraints, but spacing constraints as well.

    --
    Rick
previous month june 2013 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today