There is a way shown in WWDC AutoLayout session. Keep XIB AutoLayout enabled, then subclass the container control and override its updateConstraints method. In the very beginning call [self setAutoTranslateAutoResizingMasks:NO];
Depending on your situation, you might also need to set autoTranslateAutoReaizingMasks to NO for the child controls too. And you can verify the final constraints by printing [self constraints] in the end of this method. Hope it helps. -Jonny 在 2012-10-10,上午1:22,Roland King <r...@rols.org> 写道: > Is there a good, supported way to use Autolayout in a sort of hybrid mode > where you use IB to add and configure views, put text in labels etc, but > actually add the constraints in code using the rather clever constraint > string representation at runtime? If you turn Autolayout off for a Storyboard > then it's off for everything and you can't use it for anything, I only want > to do this for a few views/scenes, some I'm happy to configure in IB, if > Autolayout is on then IB adds constraints for everything which means you have > to either add outlets for those constraints and remove them, or crawl the > view hierarchy and remove them all them before adding your own which seems > hopelessly inefficient. I want them not to exist at all for some views until > I add them. > > The motivation for this is that IB's support for autolayout is a bit .. > random. I'm spending a LOT of time messing about trying to thwart the > auto-constraint-adding process in some views/scenes where I could express > what I want very simply using the string format. IB has a particularly nasty > habit of adding fixed width constraints to things as you move them around, > width constraints which are totally unnecessary(*) and usually 'auto > constraints' which means you can't damned well delete them. Sometimes you can > promote them to user constraints and delete them, sometimes that just makes > them come back again, sometimes you can lower their priority to 1 and then > delete them, for some bizarre reason, sometimes you can't get rid of them at > all and end up removing a view, re-adding it and doing the constraints in a > different order and that occasionally works. It wastes a sugar load of time > and just when you think you got it right, you add one more label, a fixed > width arrives randomly somewhere and you have to spend another 10 minutes > mucking about getting rid of it. If I could just say 'make the objects, use > autolayout, I'll add the constraints myself in code' and then deal with any > of the layout exceptions myself, the exceptions being quite rich and easy to > understand, I could build things faster and with less frustration. And I want > to do this on a per-view or at least per-scene level in a storyboard. > > (*)By totally unnecessary I do mean that IB has added an auto constraint > which, if you do manage to find a way to remove it by one or other trick, > with not one single other constraint in the system changing, not one > priority, not one anything, the autolayout is still fully specified and > consistent and shows no log messages when laid out, they are constraints > which either should not be added at all, or should be added as user > constraints for extra specification which can be removed at will. Making the > text of long labels shorter is a particularly good example of this, IB > bungles this up constantly. > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/yingshen.yu%40gmail.com > > This email sent to yingshen...@gmail.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com