Layout timing (was Re: setStringValue problems with dynamically loaded views.)
Layout timing (was Re: setStringValue problems with dynamically loaded views.)
- Subject: Layout timing (was Re: setStringValue problems with dynamically loaded views.)
- From: Kevin Brock <email@hidden>
- Date: Wed, 24 Mar 2010 09:50:41 -0700
On Mar 17, 2010, at 3:20 PM, Kevin Brock wrote:
> On Mar 17, 2010, at 2:42 PM, Kyle Sluder wrote:
>> which is designed for just this kind of scenario. NSViewController
>> doesn't have an analog for -windowDidLoad; instead you are expected to
>> override -loadView, call super's implementation, and then perform your
>> setup. That is the approach I would recommend.
>
> Thanks. This fixed my problems!
Well, this fixed *some* problems. Since I'm doing dynamic layout of the controls in the window I don't know what's going to be there until runtime. The problem I'm seeing is odd, because although layout *is* being done, it's being done inaccurately. By that I mean that the frames I'm setting aren't the frames that are getting set. All of the views have wantsLayer set, and none of them are set to automatically resize subviews.
I'm doing the layout like this, where layoutFields: also does all of its layout using the animator:
[NSAnimationContext beginGrouping];
[dynamicView layoutFields];
[[window animator] setFrame:window_frame display:YES];
[[dynamicView animator] setFrame:view_rect];
[NSAnimationContext endGrouping];
[auth_contents layoutFields];
The required height of the window is calculated from the controls, and here's an example of the values that are getting set:
--> -[mydlg initWithTemplate:andDelegate:]
XIB loaded.
<-- -[mydlg initWithTemplate:andDelegate:]
--> -[mydlg windowDidLoad]
--> -[dynamicView initWithTemplate:andDelegate:]
XIB loaded.
--> -[dynamicView loadView]
<-- -[dynamicView loadView]
<-- -[dynamicView initWithTemplate:andDelegate:]
Initialized dynamic view.
Window rect: X = 22, Y = 442, W = 340, H = 292
Dyn View rect: X = 20, Y = 20, W = 300, H = 230
--> -[dynamicView layoutFields]
Field 2 rect: X = 0, Y = 0, W = 84, H = 22
Field 1 rect: X = 0, Y = 44, W = 225, H = 22
Label 1 rect: X = 0, Y = 70, W = 225, H = 17
Field 0 rect: X = 0, Y = 95, W = 225, H = 22
Label 0 rect: X = 0, Y = 121, W = 225, H = 17
<-- -[dynamicView layoutFields]
Window rect (after): X = 22, Y = 526, W = 340, H = 208
Dyn View rect (after): X = 20, Y = 20, W = 300, H = 146
<-- -[mydlg windowDidLoad]
But the values aren't getting set correctly. For example the view might get a Y position of -3, or 0, field 0 might be at 87 instead of 95, and everything else might be fine. The confusing part is that the layout *is* getting done, and its *almost* right. I'd understand it if it wasn't getting done at all, but why the inaccuracies? All of the numbers are floats, they're just shown here as ints.
Any thoughts on this? Maybe I should be doing the layout later in the load process, but I thought that once the view was loaded that would be enough to layout the visible pieces... Order of the calls to setFrame: doesn't affect anything.
Any pointers would be appreciated.
Kevin
_______________________________________________
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