Re: NSSplitView not Resizing Subviews if Delegate is used
Re: NSSplitView not Resizing Subviews if Delegate is used
- Subject: Re: NSSplitView not Resizing Subviews if Delegate is used
- From: Chuck Soper <email@hidden>
- Date: Tue, 19 Feb 2013 15:31:26 -0800
- Thread-topic: NSSplitView not Resizing Subviews if Delegate is used
Autolayout works well with NSSplitView. There may be differences between
10.7 or 10.8 but I can't remember. Does your app require Mac OS X 10.8 or
10.7?
The way I use autolayout with NSSplitView is to add constraints to the
subviews in IB. If you need to add or remove those constraints, you can
connect the constraints in IB as ivars, then add/remove them to your view
as necessary. I'm not sure if I'm explaining this very well, one of these
WWDC videos explains it quite well:
WWDC 2012: Introduction to Auto Layout for iOS and OS X
<https://developer.apple.com/videos/wwdc/2012/?id=202>
WWDC 2012: Auto Layout by Example
<https://developer.apple.com/videos/wwdc/2012/?id=232>
WWDC 2012: Best Practices for Mastering Auto Layout
<https://developer.apple.com/videos/wwdc/2012/?id=228>
When I first looked into using autolayout, I thought that it was best to
implement split views without NSSplitView. The reason I thought this was
because one of the autolayout samples (link below) shows how to implement
split views without NSSplitView. It says that this approach is "a lot
simpler." But, I think the comment means writing this sample code is
simpler then writing NSSplitView from scratch.
<http://developer.apple.com/library/mac/#samplecode/Cocoa_Autolayout_Demos/
Introduction/Intro.html#//apple_ref/doc/uid/DTS40010636-Intro-DontLinkEleme
ntID_2>
I think that using NSSplitView with autolayout is simpler than attempting
to write split views without NSSplitView but I didn't discover this by
reading the documentation.
Here's a response that I got a few months ago that was very helpful:
http://lists.apple.com/archives/cocoa-dev/2012/Nov/msg00463.html
hope this helps,
Chuck
On 2/19/13 2:28 PM, "Michael Starke"
<email@hidden> wrote:
>I was thinking about Auto-Layout and indeed it is the source of the
>Problem.
>
>Even if the delgate just had
>- (BOOL)splitView:(NSSplitView *)splitView
>shouldAdjustSizeOfSubview:(NSView *)view {
> return YES;
>}
>the resizing did not work anymore.
>
>The proposedMinimumPosition was just the input, which is 0. I just wanted
>to implement a method without altering the behavior (which this should
>have done if i read the header documentation correctly)
>
>
>Anyway. Disabling Autolayout fixed all the quirks. How does one use a
>Splitter with Autolayout? Do I have to add custom constraints to the
>content views?
>
>On 19.02.2013, at 18:22, Chuck Soper <email@hidden> wrote:
>
>> Are you using Auto Layout in InterfaceBuilder? (See the Use Auto Layout
>> checkbox in the File inspector for each nib.) If so, implementing
>> splitView:constrainMinCoordinate:ofSubviewAt: may conflict with auto
>> layout.
>>
>> Also, what is your purposed minimum? Where is it defined?
>>
>> Chuck
>>
>>
>> On 2/19/13 7:53 AM, "Michael Starke"
>> <email@hidden> wrote:
>>
>>> Hello here,
>>>
>>> Yesterday a ran into a strange problem that I could not get my head
>>> around. Simple setup created in InterfaceBuilder:
>>>
>>> A window with a horizontal NSSplitview with two subviews.
>>>
>>> If I run this without setting the delegate of the split view the two
>>> subviews get rescaled as expected.
>>> When I hook up a delegate (for example via InterfaceBuilder) and the
>>> delegate does not implement any of the @optionals, all is fine.
>>>
>>> But when I just add one implementation, e.g:
>>>
>>> - (CGFloat)splitView:(NSSplitView *)splitView
>>> constrainMinCoordinate:(CGFloat)proposedMinimumPosition
>>> ofSubviewAt:(NSInteger)dividerIndex {
>>> return proposedMinimumPosition;
>>> }
>>>
>>> Which should interfere in any way, all goes down the drain. If i drag
>>>the
>>> Splitter, the left view gets resized, the right view just stays the
>>>same
>>> If the delegate implements
>>>
>>> - (void)splitViewDidResizeSubviews:(NSNotification *)notification
>>>
>>> I just get notified for resizing the first view, not the second
>>>
>>> Am I to stupid to see my error? Or might this be a bug?
>>>
>>> Any help would be great,
>>> Michael
>>>
>>>
>>>
>>> ___m i c h a e l s t a r k e____
>>> geschäftsführer
>>> HicknHack Software GmbH
>>> www.hicknhack-software.com
>>>
>>> ___k o n t a k t____
>>> +49 (170) 3686136
>>> email@hidden
>>>
>>> ___H i c k n H a c k S o f t w a r e G m b H____
>>> geschäftsführer - maik lathan | andreas reischuck | michael starke
>>> bayreuther straße 32
>>> 01187 dresden
>>> amtsgericht dresden HRB 30351
>>> sitz - dresden
>>>
>>>
>>> _______________________________________________
>>>
>>> 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
>>
>>
>
>
>___m i c h a e l s t a r k e____
> geschäftsführer
> HicknHack Software GmbH
> www.hicknhack-software.com
>
>___k o n t a k t____
> +49 (170) 3686136
> email@hidden
>
>___H i c k n H a c k S o f t w a r e G m b H____
> geschäftsführer - maik lathan | andreas reischuck | michael starke
> bayreuther straße 32
> 01187 dresden
> amtsgericht dresden HRB 30351
> sitz - dresden
>
>
>_______________________________________________
>
>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
_______________________________________________
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