I've run into a rather odd Yosemite bug (filed as rdar://20965476) when swapping the toolbar of an NSWindow.
Specifically, for Yosemite-style windows, calling setToolbar (to replace an existing toolbar with a different one) causes the window to spontaneously resize, stretching the content. This is clearly a bug.
The question is, how to work around this bug? I've tried all sorts of approaches, with no success.
The bug can be reproduced by modifying Apple's ToolbarSample sample code project (https://developer.apple.com/library/mac/samplecode/ToolbarSample/Introduction/Intro.html), as follows:
1. Add the following to the end of -awakeFromNib in Controller.m:
self.window.titleVisibility = NSWindowTitleHidden; // Yosemite-style toolbar
NSRect frame = self.window.frame; // Set the window to a small fixed size at launch
frame.origin.y += frame.size.height - 400;
frame.size.height = 400;
[self.window setFrame:frame display:YES];
[self performSelector:@selector(tweakToolbar:) withObject:nil afterDelay:0.5f];
2. Add the following method to Controller.m:
- (void)tweakToolbar:(id)object {
[self.window setToolbar:self.window.toolbar]; // should have no effect
[self performSelector:@selector(tweakToolbar:) withObject:nil afterDelay:0.5f];
}
When run, this code repeatedly sets the window's toolbar to itself, which should have no effect. But the window unexpectedly gets taller with each call!
Any help finding a workaround would be tremendously appreciated.
Thanks in advance,
Ben