On Nov 26, 2014, at 2:00 AM, Gerriet M. Denkmann <[email protected]> wrote:
> On 26 Nov 2014, at 13:15, Ken Thomases <[email protected]> wrote: >> >> Finally, have you considered leaving >> translatesAutoresizingMaskIntoConstraints set to YES for the view and >> setting its autoresizing mask? In that case, calls to set the frame will >> establish constraints that will maintain that new frame as per the old >> springs-and-struts model of the autoresizing mask. > > Did change in Xcode "Use Auto Layout" to off for my CustomView. > But this did turn off Auto Layout for ALL things in the window. Not quite > what I had in mind. So: back to "On". There's no view-specific "Use Auto Layout" setting. You were probably looking at the File inspector, which, of course, is for the file as a whole. > Then I added in my CustomView: > > - (instancetype)initWithFrame:(NSRect)frameRect > { > self = [ super initWithFrame: frameRect ]; > if ( self == nil ) return nil; > self.translatesAutoresizingMaskIntoConstraints = YES; > self.autoresizingMask = NSViewHeightSizable; > return self; > } > > But still AutoLayout was messing with my view, setting its size to (0,0). The NIB-loading machinery would set translatesAutoresizingMaskIntoConstraints to NO after it has instantiated your view, so it would effectively override what you set in your init method. > Finally I settled with: > > - (void)windowDidLoad > { > [super windowDidLoad]; > [ self performSelector: @selector(updateFrame:) withObject: @(0) > afterDelay: 1 ]; > } > > This has the (small) disadvantage that the window initially shows a boring > grey custom view for one second. And the view could be reset to have zero size at any time, whenever the auto layout system lays out the view hierarchy again. Don't try to bypass auto layout. It's only going to end in frustration. When you're using auto layout, either have your view class report an intrinsic size, set up constraints to maintain its size, or set translatesAutoresizingMaskIntoConstraints. You can do the latter in -windowDidLoad and it won't be overridden by the NIB-loading machinery. Regards, Ken _______________________________________________ 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]
