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: Chuck Soper <email@hidden>
- Date: Tue, 27 Nov 2012 18:33:12 -0800
- Thread-topic: split views, best practices for 10.8?
Hi Peter,
Wow, your email helped me quite a bit.
On 11/27/12 2:11 PM, "Peter Ammon" <email@hidden> wrote:
>Hi Chuck,
>
>Autolayout works well with NSSplitView in 10.8.
Perfect. Thanks for that confirmation.
Seeing an AutoLayout sample code called SplitView which doesn't use
NSSplitView left me wondering what the recommended approach was. And the
ReadMe for Cocoa_Autolayout_Demos kind of implies that auto layout split
views are the way to go. I suppose it depends on the situation.
>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.
Excellent. I'm taking that approach for the third view in the NSSplitView
instance as well.
>>
>> 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.
I thought that setting the Holding Priority wouldn't work for the third
rightmost view, but it does. I was impressed to see three Hugging
Priorities for Left, Middle and Right views within the NSSplitView
instance in Xcode.
>>
>>
>> 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
Thanks, I'll look into this. I do want to resize the window, so I'll try
what you're recommending below.
>You could also try using setPosition:ofDividerAtIndex:.
This works within the given constraints. So, I could possibly remove a
constraint before sending setPosition:ofDividerAtIndex: to hide the view.
I would need to add animate the movement, and I can't recall how to do
that.
>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.
Yes, I want to animate a split view and have the window size as a result -
just like the Reminders app.
I think that I need to programmatically resize window with smooth
animation. I need to look into how to do that, but I suspect that it'll be
straightforward.
>>
>>
>> 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.
Wow, that capability was news to me! In Xcode/IB, simply dragging an
NSView into the NSSplitView added a third subview. Amazing.
I may need to add an horizontal NSSplitView to one of the subviews of the
vertical NSSplitView. I just tested that, it appears to work fine.
>Hope that helps!
>-Peter
It helps immensely! Thanks!
Chuck
_______________________________________________
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