• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Troubles with auto-layout
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Troubles with auto-layout


  • Subject: Troubles with auto-layout
  • From: Martin Hewitson <email@hidden>
  • Date: Sun, 26 Aug 2012 13:00:34 +0200

Dear list,

I wanted to change the way some components in my app resize, and it seemed sensible to use auto-layout to achieve this (because it seemed impossible/hard to do with the old springs and struts method).

The view hierarchy is roughly like this:

Window
	- Splitview
		- Outline view
		- Tabview
			- tab1
			- tab2
			- tab3

The view in each tab comes from their own xib and I add them programatically at app launch.

The outline view is constrained to have a minimum size and the splitview has a higher holding priority on the left pane.

All works well except for tab2. For some reason when I resize the window the view in tab2 remains a fixed width and the splitview divider moves, so that the outline view resizes. The views in the tabs are all rather similar and I can't see that I've got any constraints which are dramatically different on any of the three tabs. Of course, I may have, which is partly why I'm writing this mail. I'm finding it very tricky to debug the behaviour of auto-layout, so any clues in that respect will be gratefully received.

Q1) What could I have done on tab2's view that causes the splitview to move rather than the view to resize when I resize the window?

Additionally, I saw in the WWDC2012 videos on the topic that one should never call -setFrame: on views which are controlled by auto-layout. Which brings me to a side question. When I add the views to the tab content views at app launch, I do something like this:

  self.panel = [[PanelViewController alloc] initWithDelegate:self];
  [self.panel.view setFrame:[self.panelContainer bounds]];
  [self.panelContainer addSubview:self.panel.view];

Q2) How should I replace this -setFrame: call for auto-layout? If I simply miss it out, the view gets a zero size (at least I assume so since it doesn't appear). I've tried adding constraints so that it has fixed offsets of zero from its superview, but that caused other strange behaviour. So what's the correct procedure?

Adding these constraints:

  NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view(==superview)]|"
                                                                 options:NSLayoutFormatAlignAllLeft
                                                                 metrics:nil
                                                                   views:@{@"view" : self.panel.view, @"superview" : self.panelContainer}
                          ];

  [self.panelContainer addConstraints:constraints];
  constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view(==superview)]|"
                                                        options:NSLayoutFormatAlignAllBottom
                                                        metrics:nil
                                                          views:@{@"view" : self.panel.view, @"superview" : self.panelContainer}
                 ];

  [self.panelContainer addConstraints:constraints];

gives me "Unable to simultaneously satisfy constraints" exceptions. I've watched the three WWDC2012 videos related to auto-layout but I haven't quite found any examples of quite what I want to do, or how to debug the behaviour I see.

Many thanks,

Martin
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: NSView -backingAlignedRect:
  • Next by Date: Distributed Objects
  • Previous by thread: Re: NSScrollView scroll scale image problem
  • Next by thread: Distributed Objects
  • Index(es):
    • Date
    • Thread