On Saturday, December 13, 2014 at 9:24 AM, Charles Jenkins wrote:
>  
> What else should I look for to determine why my window became unresizable?
Well, I found it, and I’d like your opinions on whether it’s a bug that should 
be reported to Apple.

My app is a document-based app where the main user interface is a document 
window mostly taken up by an NSSplitView. Even though Finder isn’t 
document-based, it’s a good example of what my app looks like: the main part of 
the window is filled with a Split View containing a Source View on the left of 
the splitter, other content on the right. The window also has a Toolbar.

If we use Auto Layout to put all these things together to mimic Finder, it just 
doesn’t work. Here are steps to create a sample app to demonstrate:

1. In Xcode, start a new project: a Document-based Cocoa application using 
Objective-C.

2. Click on Document.xib to work in the main window. Start by deleting the 
“your document contents here” label.

3. Make sure the window is selected, and in the Attributes Inspector, change 
the Full Screen setting to “Primary Window.”

4. Drag in a Vertical Split View and plop it in the middle of the window.

5. With the Split View selected, click on the widget that adds constraints.

6. Working only in the top of the constraint-definition popup window, put 
zeroes in all four boxes to indicate that no space should be left between the 
edges of the Split View and its superview. Make sure the red I-beams are all 
solid to indicate that all your entries are meaningful.

7. At the bottom of the popup window, change the Update Frames setting to 
“Items of New Constraints” and then click on the button which says “Add 4 
Constraints.” The Split View should grow to fill the window.

8. Create an IBOutlet named “splitView” for the Split View and an IBOutlet 
named “splitLeftSide” for the Custom View on the left side of the splitter.

9. Edit Document.h to add “<NSSplitViewDelegate>” after “NSDocument.”

10. Edit Document.m to add this function:

-(BOOL)         splitView:(NSSplitView*)splitView
shouldAdjustSizeOfSubview:(NSView*)view
{
  return ( view != self.splitLeftSide );
}

11. In windowControllerDidLoadNib:, set self.splitView.delegate = self.

12. Build and run the app. Open a new document window and mess with it to 
verify it works as expected: the Split View fills the window; resizing works; 
and when you enter Full Screen mode, the Split View fills the screen. The left 
side of the split will remain the same width unless you drag the splitter 
around.

13. Quit the app and return to Interface Builder. Drag in a Toolbar. Now you’ve 
done it!

14. Build and run the app to verify that we’re now broken. Now instead of the 
Split View being pinned to the window, the constraints work backward: the 
window is pinned to the Split View. Resize arrows don’t appear when you hover 
the mouse cursor near an edge. You can’t resize the window by any means, not 
even by using Divvy, and Full Screen mode is really ugly, leaving most of the 
screen black.

You can fix the problem by (a) deleting the Toolbar, (b) commenting out the 
line of code introduced in step 11, or (c) turning off Auto Layout for the NIB 
and using struts and springs to make the Split View fill the window. (Depending 
on your version, Xcode may crash when you try to turn off Auto Layout.)

What surprisingly does NOT work is to make splitView:shouldAdjustSizeOfSubview: 
always return YES. Apparently simply setting the Split View's delegate is 
enough to wreck Auto Layout when a toolbar is present.

_______________________________________________

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

Reply via email to