On Nov 26, 2012, at 6:07 PM, Ken Ferry <[email protected]> wrote: > Think of setFrame: outside of layout the same way you think of drawing > outside of drawRect: > > It will "work" in the sense that the frame will be changed, but it's just > going to get stomped the next time the layout pass comes around.
Actually, in certain cases it won't "just work." In particular, on Mac OS X, if a view doesn't have *any* constraints defining its position, -[NSView resizeWithOldSuperviewSize:] will attempt to solve the constraints applying to the view, realize their are none, and set its frame to NSZeroRect. Worse, -resizeWithOldSuperviewSize: does *NOT* call -layout or -updateConstraints! It just runs the constraint system with whatever constraints happen to be installed at that time. If your timing is particularly unfortunate, this will happen to before the first time -updateConstraints is called for your window (like, say, during your window controller's -windowDidLoad, while you're setting up your window's toolbar). Then, when the view gets -updateConstraints for the first time, it will install mandatory autoresizing mask constraints that force its frame to NSZeroRect, which are certain to conflict with any constraints your override of -updateConstraints installs. Since autoresizing masks aren't translated into constraints until -updateConstraints is called, even—that is to say, *especially*—views that you expect to be taken care of by this compatibility feature are prone to this circumstance. Moral of the story: if you override -layout, you must either turn on translatesAutoresizingMaskIntoConstraints for your subviews or you must fully specify the view's frame using constraints. It is insufficient to merely override -layout to call -setFrame:. And if you anything calls -resizeSubviewsWithOldSize: on your window's content view before the first -updateConstraints pass, you are boned. --Kyle Sluder _______________________________________________ Cocoa-dev mailing list ([email protected]) 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 [email protected]
