Re: split views, best practices for 10.8?
Re: split views, best practices for 10.8?
- Subject: Re: split views, best practices for 10.8?
- From: Peter Ammon <email@hidden>
- Date: Tue, 27 Nov 2012 14:11:32 -0800
Hi Chuck,
Autolayout works well with NSSplitView in 10.8.
On Nov 27, 2012, at 10:27 AM, Chuck Soper <email@hidden> wrote:
> Hi, I'm writing a Mac app for 10.8 (with Xcode 4.5.2) and I need to
> implement a layout similar to iPhoto. I think that the way to do use an
> NSSplitView with the right view containing another NSSplitView like this:
> [ sourceView | [ contentView | infoView ] ]
>
>
> I considered relying entirely on auto layout and avoiding NSSplitView, but
> it seems like too much work and that NSSplitView provides good
> functionality. Some auto layout sample code shows how to implement a split
> view without using NSSplitView. One WWDC 2012 auto layout session shows
> how to use auto layout to enhance NSSplitView. At the moment, I think that
> using NSSplitView with auto layout is the way to go.
>
> I need to include the follow features:
> 1. Constrain the sourceView and infoView to a min/max widths.
> I have this working using auto layout constraints. I haven't yet looked
> into constraining the split position using NSSplitView instance methods.
Adding min/max constraints is the right way to do this. The NSSplitView delegate methods will kick you out of autolayout mode.
>
> 2. Give the contentView priority (allow it to resize and hold the other
> views) when resizing the window.
> I have this working by increasing the Holding Priority of the Left View of
> the NSSplitView. (I haven't implemented the nested split view yet.)
Sounds good.
>
>
> 3. Programmatically show/hide the sourceView and infoView with smooth
> animation. The Reminders app does this very well. I can't figure out how
> to do this. I think that adding and removing constraints in the action
> method to show/hide the sourceView is the correct approach, but I don't
> have that working yet. I noticed that setting the sourceView (the left
> view of an NSSplitView) to zero width using auto layout constraints does
> not cause isSubviewCollapsed:sourceView to return true. I don't know the
> recommended way to programmatically show/hide one view of an NSSplitView.
> Or, if avoiding NSSplitView and using auto layout is a possible solution.
If you want to animate a split view without changing the window size, try this:
- Add a constraint to the view that sets its width equal to its current width
- Call [[constraint animator] setConstant:0];
- Remove the constraint once the animation is done
You could also try using setPosition:ofDividerAtIndex:.
If you want to animate a split view while also changing the window size, adjust the holding priority so that the pane that you want to grow has the lowest priority, and just resize the window.
>
>
> One more issue:
> My NSWindowController nib file has "Use Auto Layout" checked. When I
> attempt to add an NSSplitView to the right view of another NSSplitView,
> Xcode/IB adds many suggested constraints that dramatically changes the
> existing behavior of my first NSSplitView, so much so that I don't know
> how to restore or fix it. Has anyone else had problems with this? I see
> two possible solutions:
> a. Turn off "Use Auto Layout" in the nib file and add this class method to
> the contentView of the window:
> + (BOOL)requiresConstraintBasedLayout { return YES; }
> This prevents IB from messing with my constraints.
> b. Add the nested NSSplitView to its own nib file and programmatically add
> it as a subview to the right view of the other NSSplitView.
Are you sure you need a nested split view at all? A single split view can have multiple panes.
Hope that helps!
-Peter
_______________________________________________
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